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
25 #define NONAMELESSSTRUCT
33 #include "wine/list.h"
34 #include "wine/debug.h"
36 #include "explorerframe_main.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(nstc
);
40 typedef struct nstc_root
{
44 NSTCROOTSTYLE root_style
;
45 IShellItemFilter
*pif
;
50 INameSpaceTreeControl2 INameSpaceTreeControl2_iface
;
51 IOleWindow IOleWindow_iface
;
57 WNDPROC tv_oldwndproc
;
63 INameSpaceTreeControlEvents
*pnstce
;
66 static const DWORD unsupported_styles
=
67 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
| NSTCS_FAVORITESMODE
|
68 NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
| NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
|
69 NSTCS_SHOWREFRESHBUTTON
| NSTCS_SPRINGEXPAND
| NSTCS_RICHTOOLTIP
| NSTCS_NOINDENTCHECKS
;
70 static const DWORD unsupported_styles2
=
71 NSTCS2_INTERRUPTNOTIFICATIONS
| NSTCS2_SHOWNULLSPACEMENU
| NSTCS2_DISPLAYPADDING
|
72 NSTCS2_DISPLAYPINNEDONLY
| NTSCS2_NOSINGLETONAUTOEXPAND
| NTSCS2_NEVERINSERTNONENUMERATED
;
74 static inline NSTC2Impl
*impl_from_INameSpaceTreeControl2(INameSpaceTreeControl2
*iface
)
76 return CONTAINING_RECORD(iface
, NSTC2Impl
, INameSpaceTreeControl2_iface
);
79 static inline NSTC2Impl
*impl_from_IOleWindow(IOleWindow
*iface
)
81 return CONTAINING_RECORD(iface
, NSTC2Impl
, IOleWindow_iface
);
84 /* Forward declarations */
85 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
);
87 /*************************************************************************
88 * NamespaceTree event wrappers
90 static HRESULT
events_OnGetDefaultIconIndex(NSTC2Impl
*This
, IShellItem
*psi
,
91 int *piDefaultIcon
, int *piOpenIcon
)
95 if(!This
->pnstce
) return E_NOTIMPL
;
97 refcount
= IShellItem_AddRef(psi
);
98 ret
= INameSpaceTreeControlEvents_OnGetDefaultIconIndex(This
->pnstce
, psi
, piDefaultIcon
, piOpenIcon
);
99 if(IShellItem_Release(psi
) < refcount
- 1)
100 ERR("ShellItem was released by client - please file a bug.\n");
104 static HRESULT
events_OnItemAdded(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
108 if(!This
->pnstce
) return S_OK
;
110 refcount
= IShellItem_AddRef(psi
);
111 ret
= INameSpaceTreeControlEvents_OnItemAdded(This
->pnstce
, psi
, fIsRoot
);
112 if(IShellItem_Release(psi
) < refcount
- 1)
113 ERR("ShellItem was released by client - please file a bug.\n");
117 static HRESULT
events_OnItemDeleted(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
121 if(!This
->pnstce
) return S_OK
;
123 refcount
= IShellItem_AddRef(psi
);
124 ret
= INameSpaceTreeControlEvents_OnItemDeleted(This
->pnstce
, psi
, fIsRoot
);
125 if(IShellItem_Release(psi
) < refcount
- 1)
126 ERR("ShellItem was released by client - please file a bug.\n");
130 static HRESULT
events_OnBeforeExpand(NSTC2Impl
*This
, IShellItem
*psi
)
134 if(!This
->pnstce
) return S_OK
;
136 refcount
= IShellItem_AddRef(psi
);
137 ret
= INameSpaceTreeControlEvents_OnBeforeExpand(This
->pnstce
, psi
);
138 if(IShellItem_Release(psi
) < refcount
- 1)
139 ERR("ShellItem was released by client - please file a bug.\n");
143 static HRESULT
events_OnAfterExpand(NSTC2Impl
*This
, IShellItem
*psi
)
147 if(!This
->pnstce
) return S_OK
;
149 refcount
= IShellItem_AddRef(psi
);
150 ret
= INameSpaceTreeControlEvents_OnAfterExpand(This
->pnstce
, psi
);
151 if(IShellItem_Release(psi
) < refcount
- 1)
152 ERR("ShellItem was released by client - please file a bug.\n");
156 static HRESULT
events_OnItemClick(NSTC2Impl
*This
, IShellItem
*psi
,
157 NSTCEHITTEST nstceHitTest
, NSTCECLICKTYPE nstceClickType
)
161 if(!This
->pnstce
) return S_OK
;
163 refcount
= IShellItem_AddRef(psi
);
164 ret
= INameSpaceTreeControlEvents_OnItemClick(This
->pnstce
, psi
, nstceHitTest
, nstceClickType
);
165 if(IShellItem_Release(psi
) < refcount
- 1)
166 ERR("ShellItem was released by client - please file a bug.\n");
170 static HRESULT
events_OnSelectionChanged(NSTC2Impl
*This
, IShellItemArray
*psia
)
172 if(!This
->pnstce
) return S_OK
;
174 return INameSpaceTreeControlEvents_OnSelectionChanged(This
->pnstce
, psia
);
177 static HRESULT
events_OnKeyboardInput(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
179 if(!This
->pnstce
) return S_OK
;
181 return INameSpaceTreeControlEvents_OnKeyboardInput(This
->pnstce
, uMsg
, wParam
, lParam
);
184 /*************************************************************************
185 * NamespaceTree helper functions
187 static DWORD
treeview_style_from_nstcs(NSTC2Impl
*This
, NSTCSTYLE nstcs
,
188 NSTCSTYLE nstcs_mask
, DWORD
*new_style
)
190 DWORD old_style
, tv_mask
= 0;
191 TRACE("%p, %x, %x, %p\n", This
, nstcs
, nstcs_mask
, new_style
);
194 old_style
= GetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
);
196 old_style
= /* The default */
197 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
|
198 WS_TABSTOP
| TVS_NOHSCROLL
| TVS_NONEVENHEIGHT
| TVS_INFOTIP
|
199 TVS_EDITLABELS
| TVS_TRACKSELECT
;
201 if(nstcs_mask
& NSTCS_HASEXPANDOS
) tv_mask
|= TVS_HASBUTTONS
;
202 if(nstcs_mask
& NSTCS_HASLINES
) tv_mask
|= TVS_HASLINES
;
203 if(nstcs_mask
& NSTCS_FULLROWSELECT
) tv_mask
|= TVS_FULLROWSELECT
;
204 if(nstcs_mask
& NSTCS_HORIZONTALSCROLL
) tv_mask
|= TVS_NOHSCROLL
;
205 if(nstcs_mask
& NSTCS_ROOTHASEXPANDO
) tv_mask
|= TVS_LINESATROOT
;
206 if(nstcs_mask
& NSTCS_SHOWSELECTIONALWAYS
) tv_mask
|= TVS_SHOWSELALWAYS
;
207 if(nstcs_mask
& NSTCS_NOINFOTIP
) tv_mask
|= TVS_INFOTIP
;
208 if(nstcs_mask
& NSTCS_EVENHEIGHT
) tv_mask
|= TVS_NONEVENHEIGHT
;
209 if(nstcs_mask
& NSTCS_DISABLEDRAGDROP
) tv_mask
|= TVS_DISABLEDRAGDROP
;
210 if(nstcs_mask
& NSTCS_NOEDITLABELS
) tv_mask
|= TVS_EDITLABELS
;
211 if(nstcs_mask
& NSTCS_CHECKBOXES
) tv_mask
|= TVS_CHECKBOXES
;
215 if(nstcs
& NSTCS_HASEXPANDOS
) *new_style
|= TVS_HASBUTTONS
;
216 if(nstcs
& NSTCS_HASLINES
) *new_style
|= TVS_HASLINES
;
217 if(nstcs
& NSTCS_FULLROWSELECT
) *new_style
|= TVS_FULLROWSELECT
;
218 if(!(nstcs
& NSTCS_HORIZONTALSCROLL
)) *new_style
|= TVS_NOHSCROLL
;
219 if(nstcs
& NSTCS_ROOTHASEXPANDO
) *new_style
|= TVS_LINESATROOT
;
220 if(nstcs
& NSTCS_SHOWSELECTIONALWAYS
) *new_style
|= TVS_SHOWSELALWAYS
;
221 if(!(nstcs
& NSTCS_NOINFOTIP
)) *new_style
|= TVS_INFOTIP
;
222 if(!(nstcs
& NSTCS_EVENHEIGHT
)) *new_style
|= TVS_NONEVENHEIGHT
;
223 if(nstcs
& NSTCS_DISABLEDRAGDROP
) *new_style
|= TVS_DISABLEDRAGDROP
;
224 if(!(nstcs
& NSTCS_NOEDITLABELS
)) *new_style
|= TVS_EDITLABELS
;
225 if(nstcs
& NSTCS_CHECKBOXES
) *new_style
|= TVS_CHECKBOXES
;
227 *new_style
= (old_style
& ~tv_mask
) | (*new_style
& tv_mask
);
229 TRACE("old: %08x, new: %08x\n", old_style
, *new_style
);
231 return old_style
^*new_style
;
234 static IShellItem
*shellitem_from_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
238 tvi
.mask
= TVIF_PARAM
;
242 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
244 TRACE("ShellItem: %p\n", (void*)tvi
.lParam
);
245 return (IShellItem
*)tvi
.lParam
;
248 /* Returns the root that the given treeitem belongs to. */
249 static nstc_root
*root_for_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
251 HTREEITEM tmp
, hroot
= hitem
;
254 /* Work our way up the hierarchy */
255 for(tmp
= hitem
; tmp
!= NULL
; hroot
= tmp
?tmp
:hroot
)
256 tmp
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)hroot
);
258 /* Search through the list of roots for a match */
259 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
260 if(root
->htreeitem
== hroot
)
263 TRACE("root is %p\n", root
);
267 /* Find a shellitem in the tree, starting from the given node. */
268 static HTREEITEM
search_for_shellitem(NSTC2Impl
*This
, HTREEITEM node
,
271 IShellItem
*psi_node
;
272 HTREEITEM next
, result
= NULL
;
275 TRACE("%p, %p, %p\n", This
, node
, psi
);
277 /* Check this node */
278 psi_node
= shellitem_from_treeitem(This
, node
);
279 hr
= IShellItem_Compare(psi
, psi_node
, SICHINT_DISPLAY
, &cmpo
);
284 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
285 TVGN_CHILD
, (LPARAM
)node
);
288 result
= search_for_shellitem(This
, next
, psi
);
289 if(result
) return result
;
292 /* Try our next sibling. */
293 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
294 TVGN_NEXT
, (LPARAM
)node
);
296 result
= search_for_shellitem(This
, next
, psi
);
301 static HTREEITEM
treeitem_from_shellitem(NSTC2Impl
*This
, IShellItem
*psi
)
304 TRACE("%p, %p\n", This
, psi
);
306 root
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
311 return search_for_shellitem(This
, root
, psi
);
314 static int get_icon(LPCITEMIDLIST lpi
, UINT extra_flags
)
317 UINT flags
= SHGFI_PIDL
| SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
;
318 SHGetFileInfoW((LPCWSTR
)lpi
, 0 ,&sfi
, sizeof(SHFILEINFOW
), flags
| extra_flags
);
322 /* Insert a shellitem into the given place in the tree and return the
323 resulting treeitem. */
324 static HTREEITEM
insert_shellitem(NSTC2Impl
*This
, IShellItem
*psi
,
325 HTREEITEM hParent
, HTREEITEM hInsertAfter
)
327 TVINSERTSTRUCTW tvins
;
328 TVITEMEXW
*tvi
= &tvins
.u
.itemex
;
330 TRACE("%p (%p, %p)\n", psi
, hParent
, hInsertAfter
);
332 tvi
->mask
= TVIF_PARAM
| TVIF_CHILDREN
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_TEXT
;
333 tvi
->cChildren
= I_CHILDRENCALLBACK
;
334 tvi
->iImage
= tvi
->iSelectedImage
= I_IMAGECALLBACK
;
335 tvi
->pszText
= LPSTR_TEXTCALLBACKW
;
337 /* Every treeitem contains a pointer to the corresponding ShellItem. */
338 tvi
->lParam
= (LPARAM
)psi
;
339 tvins
.hParent
= hParent
;
340 tvins
.hInsertAfter
= hInsertAfter
;
342 hinserted
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_INSERTITEMW
, 0,
343 (LPARAM
)(LPTVINSERTSTRUCTW
)&tvins
);
345 IShellItem_AddRef(psi
);
350 /* Enumerates the children of the folder represented by hitem
351 * according to the settings for the root, and adds them to the
352 * treeview. Returns the number of children added. */
353 static UINT
fill_sublevel(NSTC2Impl
*This
, HTREEITEM hitem
)
355 IShellItem
*psiParent
= shellitem_from_treeitem(This
, hitem
);
356 nstc_root
*root
= root_for_treeitem(This
, hitem
);
357 LPITEMIDLIST pidl_parent
;
363 hr
= SHGetIDListFromObject((IUnknown
*)psiParent
, &pidl_parent
);
366 hr
= IShellItem_BindToHandler(psiParent
, NULL
, &BHID_SFObject
, &IID_IShellFolder
, (void**)&psf
);
369 hr
= IShellFolder_EnumObjects(psf
, NULL
, root
->enum_flags
, &peidl
);
376 while( S_OK
== IEnumIDList_Next(peidl
, 1, &pidl
, &fetched
) )
378 hr
= SHCreateShellItem(NULL
, psf
, pidl
, &psi
);
382 if(insert_shellitem(This
, psi
, hitem
, NULL
))
384 events_OnItemAdded(This
, psi
, FALSE
);
388 IShellItem_Release(psi
);
391 ERR("SHCreateShellItem failed with 0x%08x\n", hr
);
393 IEnumIDList_Release(peidl
);
396 ERR("EnumObjects failed with 0x%08x\n", hr
);
398 IShellFolder_Release(psf
);
401 ERR("BindToHandler failed with 0x%08x\n", hr
);
406 ERR("SHGetIDListFromObject failed with 0x%08x\n", hr
);
411 static HTREEITEM
get_selected_treeitem(NSTC2Impl
*This
)
413 return (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
416 static IShellItem
*get_selected_shellitem(NSTC2Impl
*This
)
418 return shellitem_from_treeitem(This
, get_selected_treeitem(This
));
421 static void collapse_all(NSTC2Impl
*This
, HTREEITEM node
)
425 /* Collapse this node first, and then first child/next sibling. */
426 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_COLLAPSE
, (LPARAM
)node
);
428 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
429 if(next
) collapse_all(This
, next
);
431 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_NEXT
, (LPARAM
)node
);
432 if(next
) collapse_all(This
, next
);
435 static HTREEITEM
treeitem_from_point(NSTC2Impl
*This
, const POINT
*pt
, UINT
*hitflag
)
442 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tviht
);
443 if(hitflag
) *hitflag
= tviht
.flags
;
447 /*************************************************************************
448 * NamespaceTree window functions
450 static LRESULT
create_namespacetree(HWND hWnd
, CREATESTRUCTW
*crs
)
452 NSTC2Impl
*This
= crs
->lpCreateParams
;
453 HIMAGELIST ShellSmallIconList
;
454 DWORD treeview_style
, treeview_ex_style
;
456 TRACE("%p (%p)\n", This
, crs
);
457 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (LPARAM
)This
);
458 This
->hwnd_main
= hWnd
;
460 treeview_style_from_nstcs(This
, This
->style
, 0xFFFFFFFF, &treeview_style
);
462 This
->hwnd_tv
= CreateWindowExW(0, WC_TREEVIEWW
, NULL
, treeview_style
,
463 0, 0, crs
->cx
, crs
->cy
,
464 hWnd
, NULL
, explorerframe_hinstance
, NULL
);
468 ERR("Failed to create treeview!\n");
469 return HRESULT_FROM_WIN32(GetLastError());
472 treeview_ex_style
= TVS_EX_DRAWIMAGEASYNC
| TVS_EX_RICHTOOLTIP
|
473 TVS_EX_DOUBLEBUFFER
| TVS_EX_NOSINGLECOLLAPSE
;
475 if(This
->style
& NSTCS_AUTOHSCROLL
)
476 treeview_ex_style
|= TVS_EX_AUTOHSCROLL
;
477 if(This
->style
& NSTCS_FADEINOUTEXPANDOS
)
478 treeview_ex_style
|= TVS_EX_FADEINOUTEXPANDOS
;
479 if(This
->style
& NSTCS_PARTIALCHECKBOXES
)
480 treeview_ex_style
|= TVS_EX_PARTIALCHECKBOXES
;
481 if(This
->style
& NSTCS_EXCLUSIONCHECKBOXES
)
482 treeview_ex_style
|= TVS_EX_EXCLUSIONCHECKBOXES
;
483 if(This
->style
& NSTCS_DIMMEDCHECKBOXES
)
484 treeview_ex_style
|= TVS_EX_DIMMEDCHECKBOXES
;
486 SendMessageW(This
->hwnd_tv
, TVM_SETEXTENDEDSTYLE
, treeview_ex_style
, 0xffff);
488 if(Shell_GetImageLists(NULL
, &ShellSmallIconList
))
490 SendMessageW(This
->hwnd_tv
, TVM_SETIMAGELIST
,
491 (WPARAM
)TVSIL_NORMAL
, (LPARAM
)ShellSmallIconList
);
495 ERR("Failed to get the System Image List.\n");
498 INameSpaceTreeControl2_AddRef(&This
->INameSpaceTreeControl2_iface
);
500 /* Subclass the treeview to get the keybord events. */
501 This
->tv_oldwndproc
= (WNDPROC
)SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
,
502 (ULONG_PTR
)tv_wndproc
);
503 if(This
->tv_oldwndproc
)
504 SetPropA(This
->hwnd_tv
, "PROP_THIS", This
);
509 static LRESULT
resize_namespacetree(NSTC2Impl
*This
)
514 GetClientRect(This
->hwnd_main
, &rc
);
515 MoveWindow(This
->hwnd_tv
, 0, 0, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, TRUE
);
520 static LRESULT
destroy_namespacetree(NSTC2Impl
*This
)
524 /* Undo the subclassing */
525 if(This
->tv_oldwndproc
)
527 SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
, (ULONG_PTR
)This
->tv_oldwndproc
);
528 RemovePropA(This
->hwnd_tv
, "PROP_THIS");
531 INameSpaceTreeControl2_RemoveAllRoots(&This
->INameSpaceTreeControl2_iface
);
533 /* This reference was added in create_namespacetree */
534 INameSpaceTreeControl2_Release(&This
->INameSpaceTreeControl2_iface
);
538 static LRESULT
on_tvn_deleteitemw(NSTC2Impl
*This
, LPARAM lParam
)
540 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
543 IShellItem_Release((IShellItem
*)nmtv
->itemOld
.lParam
);
547 static LRESULT
on_tvn_getdispinfow(NSTC2Impl
*This
, LPARAM lParam
)
549 NMTVDISPINFOW
*dispinfo
= (NMTVDISPINFOW
*)lParam
;
550 TVITEMEXW
*item
= (TVITEMEXW
*)&dispinfo
->item
;
551 IShellItem
*psi
= shellitem_from_treeitem(This
, item
->hItem
);
554 TRACE("%p, %p (mask: %x)\n", This
, dispinfo
, item
->mask
);
556 if(item
->mask
& TVIF_CHILDREN
)
560 hr
= IShellItem_GetAttributes(psi
, SFGAO_HASSUBFOLDER
, &sfgao
);
562 item
->cChildren
= (sfgao
& SFGAO_HASSUBFOLDER
)?1:0;
566 item
->mask
|= TVIF_DI_SETITEM
;
569 if(item
->mask
& (TVIF_IMAGE
|TVIF_SELECTEDIMAGE
))
573 hr
= events_OnGetDefaultIconIndex(This
, psi
, &item
->iImage
, &item
->iSelectedImage
);
576 hr
= SHGetIDListFromObject((IUnknown
*)psi
, &pidl
);
579 item
->iImage
= item
->iSelectedImage
= get_icon(pidl
, 0);
580 item
->mask
|= TVIF_DI_SETITEM
;
584 ERR("Failed to get IDList (%08x).\n", hr
);
588 if(item
->mask
& TVIF_TEXT
)
592 hr
= IShellItem_GetDisplayName(psi
, SIGDN_NORMALDISPLAY
, &display_name
);
595 lstrcpynW(item
->pszText
, display_name
, MAX_PATH
);
596 item
->mask
|= TVIF_DI_SETITEM
;
597 CoTaskMemFree(display_name
);
600 ERR("Failed to get display name (%08x).\n", hr
);
606 static BOOL
treenode_has_subfolders(NSTC2Impl
*This
, HTREEITEM node
)
608 return SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
611 static LRESULT
on_tvn_itemexpandingw(NSTC2Impl
*This
, LPARAM lParam
)
613 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
617 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
618 events_OnBeforeExpand(This
, psi
);
620 if(!treenode_has_subfolders(This
, nmtv
->itemNew
.hItem
))
622 /* The node has no children, try to find some */
623 if(!fill_sublevel(This
, nmtv
->itemNew
.hItem
))
626 /* Failed to enumerate any children, remove the expando
628 tvi
.hItem
= nmtv
->itemNew
.hItem
;
629 tvi
.mask
= TVIF_CHILDREN
;
631 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
639 static LRESULT
on_tvn_itemexpandedw(NSTC2Impl
*This
, LPARAM lParam
)
641 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
645 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
646 events_OnAfterExpand(This
, psi
);
650 static LRESULT
on_tvn_selchangedw(NSTC2Impl
*This
, LPARAM lParam
)
652 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
653 IShellItemArray
*psia
;
658 /* Note: Only supports one selected item. */
659 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
660 hr
= SHCreateShellItemArrayFromShellItem(psi
, &IID_IShellItemArray
, (void**)&psia
);
663 events_OnSelectionChanged(This
, psia
);
664 IShellItemArray_Release(psia
);
670 static LRESULT
on_nm_click(NSTC2Impl
*This
, NMHDR
*nmhdr
)
675 TRACE("%p (%p)\n", This
, nmhdr
);
677 GetCursorPos(&tvhit
.pt
);
678 ScreenToClient(This
->hwnd_tv
, &tvhit
.pt
);
679 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
681 if(tvhit
.flags
& (TVHT_NOWHERE
|TVHT_ABOVE
|TVHT_BELOW
))
684 /* TVHT_ maps onto the corresponding NSTCEHT_ */
685 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
686 hr
= events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_LBUTTON
);
688 /* The expando should not be expanded unless
690 if(tvhit
.flags
== TVHT_ONITEMBUTTON
)
699 static LRESULT
on_wm_mbuttonup(NSTC2Impl
*This
, WPARAM wParam
, LPARAM lParam
)
704 TRACE("%p (%lx, %lx)\n", This
, wParam
, lParam
);
706 tvhit
.pt
.x
= (int)(short)LOWORD(lParam
);
707 tvhit
.pt
.y
= (int)(short)HIWORD(lParam
);
709 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
711 /* Seems to generate only ONITEM and ONITEMICON */
712 if( !(tvhit
.flags
& (TVHT_ONITEM
|TVHT_ONITEMICON
)) )
715 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
716 hr
= events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_MBUTTON
);
724 static LRESULT
on_kbd_event(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
728 TRACE("%p : %d, %lx, %lx\n", This
, uMsg
, wParam
, lParam
);
730 /* Handled by the client? */
731 if(FAILED(events_OnKeyboardInput(This
, uMsg
, wParam
, lParam
)))
734 if(uMsg
== WM_KEYDOWN
)
739 psi
= get_selected_shellitem(This
);
740 FIXME("Deletion of file requested (shellitem: %p).\n", psi
);
744 hitem
= get_selected_treeitem(This
);
745 SendMessageW(This
->hwnd_tv
, TVM_EDITLABELW
, 0, (LPARAM
)hitem
);
750 /* Let the TreeView handle the key */
754 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
)
756 NSTC2Impl
*This
= (NSTC2Impl
*)GetPropA(hWnd
, "PROP_THIS");
765 if(on_kbd_event(This
, uMessage
, wParam
, lParam
))
769 case WM_MBUTTONUP
: return on_wm_mbuttonup(This
, wParam
, lParam
);
772 /* Pass the message on to the treeview */
773 return CallWindowProcW(This
->tv_oldwndproc
, hWnd
, uMessage
, wParam
, lParam
);
776 static LRESULT CALLBACK
NSTC2_WndProc(HWND hWnd
, UINT uMessage
,
777 WPARAM wParam
, LPARAM lParam
)
779 NSTC2Impl
*This
= (NSTC2Impl
*)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
784 case WM_NCCREATE
: return create_namespacetree(hWnd
, (CREATESTRUCTW
*)lParam
);
785 case WM_SIZE
: return resize_namespacetree(This
);
786 case WM_DESTROY
: return destroy_namespacetree(This
);
788 nmhdr
= (NMHDR
*)lParam
;
791 case NM_CLICK
: return on_nm_click(This
, nmhdr
);
792 case TVN_DELETEITEMW
: return on_tvn_deleteitemw(This
, lParam
);
793 case TVN_GETDISPINFOW
: return on_tvn_getdispinfow(This
, lParam
);
794 case TVN_ITEMEXPANDINGW
: return on_tvn_itemexpandingw(This
, lParam
);
795 case TVN_ITEMEXPANDEDW
: return on_tvn_itemexpandedw(This
, lParam
);
796 case TVN_SELCHANGEDW
: return on_tvn_selchangedw(This
, lParam
);
800 default: return DefWindowProcW(hWnd
, uMessage
, wParam
, lParam
);
805 /**************************************************************************
806 * INameSpaceTreeControl2 Implementation
808 static HRESULT WINAPI
NSTC2_fnQueryInterface(INameSpaceTreeControl2
* iface
,
812 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
813 TRACE("%p (%s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
816 if(IsEqualIID(riid
, &IID_INameSpaceTreeControl2
) ||
817 IsEqualIID(riid
, &IID_INameSpaceTreeControl
) ||
818 IsEqualIID(riid
, &IID_IUnknown
))
822 else if(IsEqualIID(riid
, &IID_IOleWindow
))
824 *ppvObject
= &This
->IOleWindow_iface
;
829 IUnknown_AddRef((IUnknown
*)*ppvObject
);
833 return E_NOINTERFACE
;
836 static ULONG WINAPI
NSTC2_fnAddRef(INameSpaceTreeControl2
* iface
)
838 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
839 LONG ref
= InterlockedIncrement(&This
->ref
);
841 TRACE("%p - ref %d\n", This
, ref
);
846 static ULONG WINAPI
NSTC2_fnRelease(INameSpaceTreeControl2
* iface
)
848 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
849 LONG ref
= InterlockedDecrement(&This
->ref
);
851 TRACE("%p - ref: %d\n", This
, ref
);
856 HeapFree(GetProcessHeap(), 0, This
);
857 EFRAME_UnlockModule();
864 static HRESULT WINAPI
NSTC2_fnInitialize(INameSpaceTreeControl2
* iface
,
867 NSTCSTYLE nstcsFlags
)
869 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
871 DWORD window_style
, window_ex_style
;
872 INITCOMMONCONTROLSEX icex
;
874 static const WCHAR NSTC2_CLASS_NAME
[] =
875 {'N','a','m','e','s','p','a','c','e','T','r','e','e',
876 'C','o','n','t','r','o','l',0};
878 TRACE("%p (%p, %p, %x)\n", This
, hwndParent
, prc
, nstcsFlags
);
880 if(nstcsFlags
& unsupported_styles
)
881 FIXME("0x%08x contains the unsupported style(s) 0x%08x\n",
882 nstcsFlags
, nstcsFlags
& unsupported_styles
);
884 This
->style
= nstcsFlags
;
886 icex
.dwSize
= sizeof( icex
);
887 icex
.dwICC
= ICC_TREEVIEW_CLASSES
;
888 InitCommonControlsEx( &icex
);
890 if(!GetClassInfoW(explorerframe_hinstance
, NSTC2_CLASS_NAME
, &wc
))
892 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
893 wc
.lpfnWndProc
= NSTC2_WndProc
;
896 wc
.hInstance
= explorerframe_hinstance
;
898 wc
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
899 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
900 wc
.lpszMenuName
= NULL
;
901 wc
.lpszClassName
= NSTC2_CLASS_NAME
;
903 if (!RegisterClassW(&wc
)) return E_FAIL
;
906 /* NSTCS_TABSTOP and NSTCS_BORDER affects the host window */
907 window_style
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
|
908 (nstcsFlags
& NSTCS_BORDER
? WS_BORDER
: 0);
909 window_ex_style
= nstcsFlags
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
914 rc
.left
= rc
.right
= rc
.top
= rc
.bottom
= 0;
916 This
->hwnd_main
= CreateWindowExW(window_ex_style
, NSTC2_CLASS_NAME
, NULL
, window_style
,
917 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
918 hwndParent
, 0, explorerframe_hinstance
, This
);
922 ERR("Failed to create the window.\n");
923 return HRESULT_FROM_WIN32(GetLastError());
929 static HRESULT WINAPI
NSTC2_fnTreeAdvise(INameSpaceTreeControl2
* iface
,
933 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
935 TRACE("%p (%p, %p)\n", This
, punk
, pdwCookie
);
939 /* Only one client supported */
943 hr
= IUnknown_QueryInterface(punk
, &IID_INameSpaceTreeControlEvents
,(void**)&This
->pnstce
);
953 static HRESULT WINAPI
NSTC2_fnTreeUnadvise(INameSpaceTreeControl2
* iface
,
956 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
957 TRACE("%p (%x)\n", This
, dwCookie
);
959 /* The cookie is ignored. */
963 INameSpaceTreeControlEvents_Release(This
->pnstce
);
970 static HRESULT WINAPI
NSTC2_fnInsertRoot(INameSpaceTreeControl2
* iface
,
973 SHCONTF grfEnumFlags
,
974 NSTCROOTSTYLE grfRootStyle
,
975 IShellItemFilter
*pif
)
977 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
979 struct list
*add_after_entry
;
980 HTREEITEM add_after_hitem
;
983 TRACE("%p, %d, %p, %x, %x, %p\n", This
, iIndex
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
985 new_root
= HeapAlloc(GetProcessHeap(), 0, sizeof(nstc_root
));
987 return E_OUTOFMEMORY
;
989 new_root
->psi
= psiRoot
;
990 new_root
->enum_flags
= grfEnumFlags
;
991 new_root
->root_style
= grfRootStyle
;
994 /* We want to keep the roots in the internal list and in the
995 * treeview in the same order. */
996 add_after_entry
= &This
->roots
;
997 for(i
= 0; i
< max(0, iIndex
) && list_next(&This
->roots
, add_after_entry
); i
++)
998 add_after_entry
= list_next(&This
->roots
, add_after_entry
);
1000 if(add_after_entry
== &This
->roots
)
1001 add_after_hitem
= TVI_FIRST
;
1003 add_after_hitem
= LIST_ENTRY(add_after_entry
, nstc_root
, entry
)->htreeitem
;
1005 new_root
->htreeitem
= insert_shellitem(This
, psiRoot
, TVI_ROOT
, add_after_hitem
);
1006 if(!new_root
->htreeitem
)
1008 WARN("Failed to add the root.\n");
1009 HeapFree(GetProcessHeap(), 0, new_root
);
1013 list_add_after(add_after_entry
, &new_root
->entry
);
1014 events_OnItemAdded(This
, psiRoot
, TRUE
);
1016 if(grfRootStyle
& NSTCRS_HIDDEN
)
1019 tvi
.mask
= TVIF_STATEEX
;
1020 tvi
.uStateEx
= TVIS_EX_FLAT
;
1021 tvi
.hItem
= new_root
->htreeitem
;
1023 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1026 if(grfRootStyle
& NSTCRS_EXPANDED
)
1027 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_EXPAND
,
1028 (LPARAM
)new_root
->htreeitem
);
1033 static HRESULT WINAPI
NSTC2_fnAppendRoot(INameSpaceTreeControl2
* iface
,
1034 IShellItem
*psiRoot
,
1035 SHCONTF grfEnumFlags
,
1036 NSTCROOTSTYLE grfRootStyle
,
1037 IShellItemFilter
*pif
)
1039 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1041 TRACE("%p, %p, %x, %x, %p\n",
1042 This
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1044 root_count
= list_count(&This
->roots
);
1046 return NSTC2_fnInsertRoot(iface
, root_count
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1049 static HRESULT WINAPI
NSTC2_fnRemoveRoot(INameSpaceTreeControl2
* iface
,
1050 IShellItem
*psiRoot
)
1052 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1053 nstc_root
*cursor
, *root
= NULL
;
1054 TRACE("%p (%p)\n", This
, psiRoot
);
1057 return E_NOINTERFACE
;
1059 LIST_FOR_EACH_ENTRY(cursor
, &This
->roots
, nstc_root
, entry
)
1063 hr
= IShellItem_Compare(psiRoot
, cursor
->psi
, SICHINT_DISPLAY
, &order
);
1071 TRACE("root %p\n", root
);
1074 events_OnItemDeleted(This
, root
->psi
, TRUE
);
1075 SendMessageW(This
->hwnd_tv
, TVM_DELETEITEM
, 0, (LPARAM
)root
->htreeitem
);
1076 list_remove(&root
->entry
);
1077 HeapFree(GetProcessHeap(), 0, root
);
1082 WARN("No matching root found.\n");
1087 static HRESULT WINAPI
NSTC2_fnRemoveAllRoots(INameSpaceTreeControl2
* iface
)
1089 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1090 nstc_root
*cur1
, *cur2
;
1092 TRACE("%p\n", This
);
1094 LIST_FOR_EACH_ENTRY_SAFE(cur1
, cur2
, &This
->roots
, nstc_root
, entry
)
1096 NSTC2_fnRemoveRoot(iface
, cur1
->psi
);
1103 return E_INVALIDARG
;
1106 static HRESULT WINAPI
NSTC2_fnGetRootItems(INameSpaceTreeControl2
* iface
,
1107 IShellItemArray
**ppsiaRootItems
)
1109 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1111 LPITEMIDLIST
*array
;
1115 TRACE("%p (%p)\n", This
, ppsiaRootItems
);
1117 count
= list_count(&This
->roots
);
1120 return E_INVALIDARG
;
1122 array
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPITEMIDLIST
)*count
);
1125 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1126 SHGetIDListFromObject((IUnknown
*)root
->psi
, &array
[i
++]);
1128 SHGetDesktopFolder(&psf
);
1129 hr
= SHCreateShellItemArray(NULL
, psf
, count
, (PCUITEMID_CHILD_ARRAY
)array
,
1131 IShellFolder_Release(psf
);
1133 for(i
= 0; i
< count
; i
++)
1136 HeapFree(GetProcessHeap(), 0, array
);
1141 static HRESULT WINAPI
NSTC2_fnSetItemState(INameSpaceTreeControl2
* iface
,
1143 NSTCITEMSTATE nstcisMask
,
1144 NSTCITEMSTATE nstcisFlags
)
1146 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1150 TRACE("%p (%p, %x, %x)\n", This
, psi
, nstcisMask
, nstcisFlags
);
1152 hitem
= treeitem_from_shellitem(This
, psi
);
1153 if(!hitem
) return E_INVALIDARG
;
1155 /* Passing both NSTCIS_SELECTED and NSTCIS_SELECTEDNOEXPAND results
1156 in two TVM_SETITEMW's */
1157 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTED
)
1159 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hitem
);
1160 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (LPARAM
)hitem
);
1162 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTEDNOEXPAND
)
1164 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
|TVSI_NOSINGLEEXPAND
, (LPARAM
)hitem
);
1167 /* If NSTCIS_EXPANDED is among the flags, the mask is ignored. */
1168 if((nstcisMask
|nstcisFlags
) & NSTCIS_EXPANDED
)
1170 WPARAM arg
= nstcisFlags
&NSTCIS_EXPANDED
? TVE_EXPAND
:TVE_COLLAPSE
;
1171 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, arg
, (LPARAM
)hitem
);
1174 if(nstcisMask
& NSTCIS_DISABLED
)
1175 tvi
.mask
= TVIF_STATE
| TVIF_STATEEX
;
1176 else if( ((nstcisMask
^nstcisFlags
) & (NSTCIS_SELECTED
|NSTCIS_EXPANDED
|NSTCIS_SELECTEDNOEXPAND
)) ||
1177 ((nstcisMask
|nstcisFlags
) & NSTCIS_BOLD
) ||
1178 (nstcisFlags
& NSTCIS_DISABLED
) )
1179 tvi
.mask
= TVIF_STATE
;
1185 tvi
.stateMask
= tvi
.state
= 0;
1186 tvi
.stateMask
|= ((nstcisFlags
^nstcisMask
)&NSTCIS_SELECTED
) ? TVIS_SELECTED
: 0;
1187 tvi
.stateMask
|= (nstcisMask
|nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1188 tvi
.state
|= (nstcisMask
&nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1190 if((nstcisMask
&NSTCIS_EXPANDED
)^(nstcisFlags
&NSTCIS_EXPANDED
))
1195 tvi
.uStateEx
= (nstcisFlags
&nstcisMask
)&NSTCIS_DISABLED
?TVIS_EX_DISABLED
:0;
1198 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1204 static HRESULT WINAPI
NSTC2_fnGetItemState(INameSpaceTreeControl2
* iface
,
1206 NSTCITEMSTATE nstcisMask
,
1207 NSTCITEMSTATE
*pnstcisFlags
)
1209 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1212 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcisMask
, pnstcisFlags
);
1214 hitem
= treeitem_from_shellitem(This
, psi
);
1216 return E_INVALIDARG
;
1221 tvi
.mask
= TVIF_STATE
;
1222 tvi
.stateMask
= TVIS_SELECTED
|TVIS_EXPANDED
|TVIS_BOLD
;
1224 if(nstcisMask
& NSTCIS_DISABLED
)
1225 tvi
.mask
|= TVIF_STATEEX
;
1227 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1228 *pnstcisFlags
|= (tvi
.state
& TVIS_SELECTED
)?NSTCIS_SELECTED
:0;
1229 *pnstcisFlags
|= (tvi
.state
& TVIS_EXPANDED
)?NSTCIS_EXPANDED
:0;
1230 *pnstcisFlags
|= (tvi
.state
& TVIS_BOLD
)?NSTCIS_BOLD
:0;
1231 *pnstcisFlags
|= (tvi
.uStateEx
& TVIS_EX_DISABLED
)?NSTCIS_DISABLED
:0;
1233 *pnstcisFlags
&= nstcisMask
;
1238 static HRESULT WINAPI
NSTC2_fnGetSelectedItems(INameSpaceTreeControl2
* iface
,
1239 IShellItemArray
**psiaItems
)
1241 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1242 IShellItem
*psiselected
;
1244 TRACE("%p (%p)\n", This
, psiaItems
);
1246 psiselected
= get_selected_shellitem(This
);
1253 hr
= SHCreateShellItemArrayFromShellItem(psiselected
, &IID_IShellItemArray
,
1258 static HRESULT WINAPI
NSTC2_fnGetItemCustomState(INameSpaceTreeControl2
* iface
,
1262 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1263 FIXME("stub, %p (%p, %p)\n", This
, psi
, piStateNumber
);
1267 static HRESULT WINAPI
NSTC2_fnSetItemCustomState(INameSpaceTreeControl2
* iface
,
1271 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1272 FIXME("stub, %p (%p, %d)\n", This
, psi
, iStateNumber
);
1276 static HRESULT WINAPI
NSTC2_fnEnsureItemVisible(INameSpaceTreeControl2
* iface
,
1279 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1282 TRACE("%p (%p)\n", This
, psi
);
1284 hitem
= treeitem_from_shellitem(This
, psi
);
1287 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (WPARAM
)hitem
);
1291 return E_INVALIDARG
;
1294 static HRESULT WINAPI
NSTC2_fnSetTheme(INameSpaceTreeControl2
* iface
,
1297 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1298 FIXME("stub, %p (%p)\n", This
, pszTheme
);
1302 static HRESULT WINAPI
NSTC2_fnGetNextItem(INameSpaceTreeControl2
* iface
,
1305 IShellItem
**ppsiNext
)
1307 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1308 HTREEITEM hitem
, hnext
;
1310 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcgi
, ppsiNext
);
1312 if(!ppsiNext
) return E_POINTER
;
1313 if(!psi
) return E_FAIL
;
1317 hitem
= treeitem_from_shellitem(This
, psi
);
1319 return E_INVALIDARG
;
1323 case NSTCGNI_NEXT
: tvgn
= TVGN_NEXT
; break;
1324 case NSTCGNI_NEXTVISIBLE
: tvgn
= TVGN_NEXTVISIBLE
; break;
1325 case NSTCGNI_PREV
: tvgn
= TVGN_PREVIOUS
; break;
1326 case NSTCGNI_PREVVISIBLE
: tvgn
= TVGN_PREVIOUSVISIBLE
; break;
1327 case NSTCGNI_PARENT
: tvgn
= TVGN_PARENT
; break;
1328 case NSTCGNI_CHILD
: tvgn
= TVGN_CHILD
; break;
1329 case NSTCGNI_FIRSTVISIBLE
: tvgn
= TVGN_FIRSTVISIBLE
; break;
1330 case NSTCGNI_LASTVISIBLE
: tvgn
= TVGN_LASTVISIBLE
; break;
1332 FIXME("Unknown nstcgi value %d\n", nstcgi
);
1336 hnext
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, tvgn
, (WPARAM
)hitem
);
1339 *ppsiNext
= shellitem_from_treeitem(This
, hnext
);
1340 IShellItem_AddRef(*ppsiNext
);
1347 static HRESULT WINAPI
NSTC2_fnHitTest(INameSpaceTreeControl2
* iface
,
1349 IShellItem
**ppsiOut
)
1351 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1353 TRACE("%p (%p, %p)\n", This
, ppsiOut
, ppt
);
1355 if(!ppt
|| !ppsiOut
)
1360 hitem
= treeitem_from_point(This
, ppt
, NULL
);
1362 *ppsiOut
= shellitem_from_treeitem(This
, hitem
);
1366 IShellItem_AddRef(*ppsiOut
);
1373 static HRESULT WINAPI
NSTC2_fnGetItemRect(INameSpaceTreeControl2
* iface
,
1377 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1379 TRACE("%p (%p, %p)\n", This
, psi
, prect
);
1384 hitem
= treeitem_from_shellitem(This
, psi
);
1387 *(HTREEITEM
*)prect
= hitem
;
1388 if(SendMessageW(This
->hwnd_tv
, TVM_GETITEMRECT
, FALSE
, (LPARAM
)prect
))
1390 MapWindowPoints(This
->hwnd_tv
, HWND_DESKTOP
, (POINT
*)prect
, 2);
1395 return E_INVALIDARG
;
1398 static HRESULT WINAPI
NSTC2_fnCollapseAll(INameSpaceTreeControl2
* iface
)
1400 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1402 TRACE("%p\n", This
);
1404 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1405 collapse_all(This
, root
->htreeitem
);
1410 static HRESULT WINAPI
NSTC2_fnSetControlStyle(INameSpaceTreeControl2
* iface
,
1411 NSTCSTYLE nstcsMask
,
1412 NSTCSTYLE nstcsStyle
)
1414 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1415 static const DWORD tv_style_flags
=
1416 NSTCS_HASEXPANDOS
| NSTCS_HASLINES
| NSTCS_FULLROWSELECT
|
1417 NSTCS_HORIZONTALSCROLL
| NSTCS_ROOTHASEXPANDO
|
1418 NSTCS_SHOWSELECTIONALWAYS
| NSTCS_NOINFOTIP
| NSTCS_EVENHEIGHT
|
1419 NSTCS_DISABLEDRAGDROP
| NSTCS_NOEDITLABELS
| NSTCS_CHECKBOXES
;
1420 static const DWORD host_style_flags
= NSTCS_TABSTOP
| NSTCS_BORDER
;
1421 static const DWORD nstc_flags
=
1422 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
|
1423 NSTCS_FAVORITESMODE
| NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
|
1424 NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
| NSTCS_SHOWREFRESHBUTTON
;
1425 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1427 /* Fail if there is an attempt to set an unknown style. */
1428 if(nstcsMask
& ~(tv_style_flags
| host_style_flags
| nstc_flags
))
1431 if(nstcsMask
& tv_style_flags
)
1434 treeview_style_from_nstcs(This
, nstcsStyle
, nstcsMask
, &new_style
);
1435 SetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
, new_style
);
1438 /* Flags affecting the host window */
1439 if(nstcsMask
& NSTCS_BORDER
)
1441 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
);
1442 new_style
&= ~WS_BORDER
;
1443 new_style
|= nstcsStyle
& NSTCS_BORDER
? WS_BORDER
: 0;
1444 SetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
, new_style
);
1446 if(nstcsMask
& NSTCS_TABSTOP
)
1448 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
);
1449 new_style
&= ~WS_EX_CONTROLPARENT
;
1450 new_style
|= nstcsStyle
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
1451 SetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
, new_style
);
1454 if((nstcsStyle
& nstcsMask
) & unsupported_styles
)
1455 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1456 (nstcsStyle
& nstcsMask
),
1457 (nstcsStyle
& nstcsMask
) & unsupported_styles
);
1459 This
->style
&= ~nstcsMask
;
1460 This
->style
|= (nstcsStyle
& nstcsMask
);
1465 static HRESULT WINAPI
NSTC2_fnGetControlStyle(INameSpaceTreeControl2
* iface
,
1466 NSTCSTYLE nstcsMask
,
1467 NSTCSTYLE
*pnstcsStyle
)
1469 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1470 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1472 *pnstcsStyle
= (This
->style
& nstcsMask
);
1477 static HRESULT WINAPI
NSTC2_fnSetControlStyle2(INameSpaceTreeControl2
* iface
,
1478 NSTCSTYLE2 nstcsMask
,
1479 NSTCSTYLE2 nstcsStyle
)
1481 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1482 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1484 if((nstcsStyle
& nstcsMask
) & unsupported_styles2
)
1485 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1486 (nstcsStyle
& nstcsMask
),
1487 (nstcsStyle
& nstcsMask
) & unsupported_styles2
);
1489 This
->style2
&= ~nstcsMask
;
1490 This
->style2
|= (nstcsStyle
& nstcsMask
);
1495 static HRESULT WINAPI
NSTC2_fnGetControlStyle2(INameSpaceTreeControl2
* iface
,
1496 NSTCSTYLE2 nstcsMask
,
1497 NSTCSTYLE2
*pnstcsStyle
)
1499 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1500 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1502 *pnstcsStyle
= (This
->style2
& nstcsMask
);
1507 static const INameSpaceTreeControl2Vtbl vt_INameSpaceTreeControl2
= {
1508 NSTC2_fnQueryInterface
,
1513 NSTC2_fnTreeUnadvise
,
1517 NSTC2_fnRemoveAllRoots
,
1518 NSTC2_fnGetRootItems
,
1519 NSTC2_fnSetItemState
,
1520 NSTC2_fnGetItemState
,
1521 NSTC2_fnGetSelectedItems
,
1522 NSTC2_fnGetItemCustomState
,
1523 NSTC2_fnSetItemCustomState
,
1524 NSTC2_fnEnsureItemVisible
,
1526 NSTC2_fnGetNextItem
,
1528 NSTC2_fnGetItemRect
,
1529 NSTC2_fnCollapseAll
,
1530 NSTC2_fnSetControlStyle
,
1531 NSTC2_fnGetControlStyle
,
1532 NSTC2_fnSetControlStyle2
,
1533 NSTC2_fnGetControlStyle2
1536 /**************************************************************************
1537 * IOleWindow Implementation
1540 static HRESULT WINAPI
IOW_fnQueryInterface(IOleWindow
*iface
, REFIID riid
, void **ppvObject
)
1542 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1543 TRACE("%p\n", This
);
1544 return NSTC2_fnQueryInterface(&This
->INameSpaceTreeControl2_iface
, riid
, ppvObject
);
1547 static ULONG WINAPI
IOW_fnAddRef(IOleWindow
*iface
)
1549 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1550 TRACE("%p\n", This
);
1551 return NSTC2_fnAddRef(&This
->INameSpaceTreeControl2_iface
);
1554 static ULONG WINAPI
IOW_fnRelease(IOleWindow
*iface
)
1556 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1557 TRACE("%p\n", This
);
1558 return NSTC2_fnRelease(&This
->INameSpaceTreeControl2_iface
);
1561 static HRESULT WINAPI
IOW_fnGetWindow(IOleWindow
*iface
, HWND
*phwnd
)
1563 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1564 TRACE("%p (%p)\n", This
, phwnd
);
1566 *phwnd
= This
->hwnd_main
;
1570 static HRESULT WINAPI
IOW_fnContextSensitiveHelp(IOleWindow
*iface
, BOOL fEnterMode
)
1572 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1573 TRACE("%p (%d)\n", This
, fEnterMode
);
1575 /* Not implemented */
1579 static const IOleWindowVtbl vt_IOleWindow
= {
1580 IOW_fnQueryInterface
,
1584 IOW_fnContextSensitiveHelp
1587 HRESULT
NamespaceTreeControl_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
1592 TRACE ("%p %s %p\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
1597 return CLASS_E_NOAGGREGATION
;
1599 EFRAME_LockModule();
1601 nstc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(NSTC2Impl
));
1603 nstc
->INameSpaceTreeControl2_iface
.lpVtbl
= &vt_INameSpaceTreeControl2
;
1604 nstc
->IOleWindow_iface
.lpVtbl
= &vt_IOleWindow
;
1606 list_init(&nstc
->roots
);
1608 ret
= INameSpaceTreeControl2_QueryInterface(&nstc
->INameSpaceTreeControl2_iface
, riid
, ppv
);
1609 INameSpaceTreeControl2_Release(&nstc
->INameSpaceTreeControl2_iface
);
1611 TRACE("--(%p)\n", ppv
);