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
;
873 static const WCHAR NSTC2_CLASS_NAME
[] =
874 {'N','a','m','e','s','p','a','c','e','T','r','e','e',
875 'C','o','n','t','r','o','l',0};
877 TRACE("%p (%p, %p, %x)\n", This
, hwndParent
, prc
, nstcsFlags
);
879 if(nstcsFlags
& unsupported_styles
)
880 FIXME("0x%08x contains the unsupported style(s) 0x%08x\n",
881 nstcsFlags
, nstcsFlags
& unsupported_styles
);
883 This
->style
= nstcsFlags
;
885 if(!GetClassInfoW(explorerframe_hinstance
, NSTC2_CLASS_NAME
, &wc
))
887 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
888 wc
.lpfnWndProc
= NSTC2_WndProc
;
891 wc
.hInstance
= explorerframe_hinstance
;
893 wc
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
894 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
895 wc
.lpszMenuName
= NULL
;
896 wc
.lpszClassName
= NSTC2_CLASS_NAME
;
898 if (!RegisterClassW(&wc
)) return E_FAIL
;
901 /* NSTCS_TABSTOP and NSTCS_BORDER affects the host window */
902 window_style
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
|
903 (nstcsFlags
& NSTCS_BORDER
? WS_BORDER
: 0);
904 window_ex_style
= nstcsFlags
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
909 rc
.left
= rc
.right
= rc
.top
= rc
.bottom
= 0;
911 This
->hwnd_main
= CreateWindowExW(window_ex_style
, NSTC2_CLASS_NAME
, NULL
, window_style
,
912 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
913 hwndParent
, 0, explorerframe_hinstance
, This
);
917 ERR("Failed to create the window.\n");
918 return HRESULT_FROM_WIN32(GetLastError());
924 static HRESULT WINAPI
NSTC2_fnTreeAdvise(INameSpaceTreeControl2
* iface
,
928 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
930 TRACE("%p (%p, %p)\n", This
, punk
, pdwCookie
);
934 /* Only one client supported */
938 hr
= IUnknown_QueryInterface(punk
, &IID_INameSpaceTreeControlEvents
,(void**)&This
->pnstce
);
948 static HRESULT WINAPI
NSTC2_fnTreeUnadvise(INameSpaceTreeControl2
* iface
,
951 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
952 TRACE("%p (%x)\n", This
, dwCookie
);
954 /* The cookie is ignored. */
958 INameSpaceTreeControlEvents_Release(This
->pnstce
);
965 static HRESULT WINAPI
NSTC2_fnInsertRoot(INameSpaceTreeControl2
* iface
,
968 SHCONTF grfEnumFlags
,
969 NSTCROOTSTYLE grfRootStyle
,
970 IShellItemFilter
*pif
)
972 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
974 struct list
*add_after_entry
;
975 HTREEITEM add_after_hitem
;
978 TRACE("%p, %d, %p, %x, %x, %p\n", This
, iIndex
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
980 new_root
= HeapAlloc(GetProcessHeap(), 0, sizeof(nstc_root
));
982 return E_OUTOFMEMORY
;
984 new_root
->psi
= psiRoot
;
985 new_root
->enum_flags
= grfEnumFlags
;
986 new_root
->root_style
= grfRootStyle
;
989 /* We want to keep the roots in the internal list and in the
990 * treeview in the same order. */
991 add_after_entry
= &This
->roots
;
992 for(i
= 0; i
< max(0, iIndex
) && list_next(&This
->roots
, add_after_entry
); i
++)
993 add_after_entry
= list_next(&This
->roots
, add_after_entry
);
995 if(add_after_entry
== &This
->roots
)
996 add_after_hitem
= TVI_FIRST
;
998 add_after_hitem
= LIST_ENTRY(add_after_entry
, nstc_root
, entry
)->htreeitem
;
1000 new_root
->htreeitem
= insert_shellitem(This
, psiRoot
, TVI_ROOT
, add_after_hitem
);
1001 if(!new_root
->htreeitem
)
1003 WARN("Failed to add the root.\n");
1004 HeapFree(GetProcessHeap(), 0, new_root
);
1008 list_add_after(add_after_entry
, &new_root
->entry
);
1009 events_OnItemAdded(This
, psiRoot
, TRUE
);
1011 if(grfRootStyle
& NSTCRS_HIDDEN
)
1014 tvi
.mask
= TVIF_STATEEX
;
1015 tvi
.uStateEx
= TVIS_EX_FLAT
;
1016 tvi
.hItem
= new_root
->htreeitem
;
1018 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1021 if(grfRootStyle
& NSTCRS_EXPANDED
)
1022 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_EXPAND
,
1023 (LPARAM
)new_root
->htreeitem
);
1028 static HRESULT WINAPI
NSTC2_fnAppendRoot(INameSpaceTreeControl2
* iface
,
1029 IShellItem
*psiRoot
,
1030 SHCONTF grfEnumFlags
,
1031 NSTCROOTSTYLE grfRootStyle
,
1032 IShellItemFilter
*pif
)
1034 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1036 TRACE("%p, %p, %x, %x, %p\n",
1037 This
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1039 root_count
= list_count(&This
->roots
);
1041 return NSTC2_fnInsertRoot(iface
, root_count
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1044 static HRESULT WINAPI
NSTC2_fnRemoveRoot(INameSpaceTreeControl2
* iface
,
1045 IShellItem
*psiRoot
)
1047 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1048 nstc_root
*cursor
, *root
= NULL
;
1049 TRACE("%p (%p)\n", This
, psiRoot
);
1052 return E_NOINTERFACE
;
1054 LIST_FOR_EACH_ENTRY(cursor
, &This
->roots
, nstc_root
, entry
)
1058 hr
= IShellItem_Compare(psiRoot
, cursor
->psi
, SICHINT_DISPLAY
, &order
);
1066 TRACE("root %p\n", root
);
1069 events_OnItemDeleted(This
, root
->psi
, TRUE
);
1070 SendMessageW(This
->hwnd_tv
, TVM_DELETEITEM
, 0, (LPARAM
)root
->htreeitem
);
1071 list_remove(&root
->entry
);
1072 HeapFree(GetProcessHeap(), 0, root
);
1077 WARN("No matching root found.\n");
1082 static HRESULT WINAPI
NSTC2_fnRemoveAllRoots(INameSpaceTreeControl2
* iface
)
1084 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1085 nstc_root
*cur1
, *cur2
;
1087 TRACE("%p\n", This
);
1089 LIST_FOR_EACH_ENTRY_SAFE(cur1
, cur2
, &This
->roots
, nstc_root
, entry
)
1091 NSTC2_fnRemoveRoot(iface
, cur1
->psi
);
1098 return E_INVALIDARG
;
1101 static HRESULT WINAPI
NSTC2_fnGetRootItems(INameSpaceTreeControl2
* iface
,
1102 IShellItemArray
**ppsiaRootItems
)
1104 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1106 LPITEMIDLIST
*array
;
1110 TRACE("%p (%p)\n", This
, ppsiaRootItems
);
1112 count
= list_count(&This
->roots
);
1115 return E_INVALIDARG
;
1117 array
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPITEMIDLIST
)*count
);
1120 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1121 SHGetIDListFromObject((IUnknown
*)root
->psi
, &array
[i
++]);
1123 SHGetDesktopFolder(&psf
);
1124 hr
= SHCreateShellItemArray(NULL
, psf
, count
, (PCUITEMID_CHILD_ARRAY
)array
,
1126 IShellFolder_Release(psf
);
1128 for(i
= 0; i
< count
; i
++)
1131 HeapFree(GetProcessHeap(), 0, array
);
1136 static HRESULT WINAPI
NSTC2_fnSetItemState(INameSpaceTreeControl2
* iface
,
1138 NSTCITEMSTATE nstcisMask
,
1139 NSTCITEMSTATE nstcisFlags
)
1141 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1145 TRACE("%p (%p, %x, %x)\n", This
, psi
, nstcisMask
, nstcisFlags
);
1147 hitem
= treeitem_from_shellitem(This
, psi
);
1148 if(!hitem
) return E_INVALIDARG
;
1150 /* Passing both NSTCIS_SELECTED and NSTCIS_SELECTEDNOEXPAND results
1151 in two TVM_SETITEMW's */
1152 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTED
)
1154 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hitem
);
1155 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (LPARAM
)hitem
);
1157 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTEDNOEXPAND
)
1159 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
|TVSI_NOSINGLEEXPAND
, (LPARAM
)hitem
);
1162 /* If NSTCIS_EXPANDED is among the flags, the mask is ignored. */
1163 if((nstcisMask
|nstcisFlags
) & NSTCIS_EXPANDED
)
1165 WPARAM arg
= nstcisFlags
&NSTCIS_EXPANDED
? TVE_EXPAND
:TVE_COLLAPSE
;
1166 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, arg
, (LPARAM
)hitem
);
1169 if(nstcisMask
& NSTCIS_DISABLED
)
1170 tvi
.mask
= TVIF_STATE
| TVIF_STATEEX
;
1171 else if( ((nstcisMask
^nstcisFlags
) & (NSTCIS_SELECTED
|NSTCIS_EXPANDED
|NSTCIS_SELECTEDNOEXPAND
)) ||
1172 ((nstcisMask
|nstcisFlags
) & NSTCIS_BOLD
) ||
1173 (nstcisFlags
& NSTCIS_DISABLED
) )
1174 tvi
.mask
= TVIF_STATE
;
1180 tvi
.stateMask
= tvi
.state
= 0;
1181 tvi
.stateMask
|= ((nstcisFlags
^nstcisMask
)&NSTCIS_SELECTED
) ? TVIS_SELECTED
: 0;
1182 tvi
.stateMask
|= (nstcisMask
|nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1183 tvi
.state
|= (nstcisMask
&nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1185 if((nstcisMask
&NSTCIS_EXPANDED
)^(nstcisFlags
&NSTCIS_EXPANDED
))
1190 tvi
.uStateEx
= (nstcisFlags
&nstcisMask
)&NSTCIS_DISABLED
?TVIS_EX_DISABLED
:0;
1193 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1199 static HRESULT WINAPI
NSTC2_fnGetItemState(INameSpaceTreeControl2
* iface
,
1201 NSTCITEMSTATE nstcisMask
,
1202 NSTCITEMSTATE
*pnstcisFlags
)
1204 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1207 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcisMask
, pnstcisFlags
);
1209 hitem
= treeitem_from_shellitem(This
, psi
);
1211 return E_INVALIDARG
;
1216 tvi
.mask
= TVIF_STATE
;
1217 tvi
.stateMask
= TVIS_SELECTED
|TVIS_EXPANDED
|TVIS_BOLD
;
1219 if(nstcisMask
& NSTCIS_DISABLED
)
1220 tvi
.mask
|= TVIF_STATEEX
;
1222 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1223 *pnstcisFlags
|= (tvi
.state
& TVIS_SELECTED
)?NSTCIS_SELECTED
:0;
1224 *pnstcisFlags
|= (tvi
.state
& TVIS_EXPANDED
)?NSTCIS_EXPANDED
:0;
1225 *pnstcisFlags
|= (tvi
.state
& TVIS_BOLD
)?NSTCIS_BOLD
:0;
1226 *pnstcisFlags
|= (tvi
.uStateEx
& TVIS_EX_DISABLED
)?NSTCIS_DISABLED
:0;
1228 *pnstcisFlags
&= nstcisMask
;
1233 static HRESULT WINAPI
NSTC2_fnGetSelectedItems(INameSpaceTreeControl2
* iface
,
1234 IShellItemArray
**psiaItems
)
1236 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1237 IShellItem
*psiselected
;
1239 TRACE("%p (%p)\n", This
, psiaItems
);
1241 psiselected
= get_selected_shellitem(This
);
1245 hr
= SHCreateShellItemArrayFromShellItem(psiselected
, &IID_IShellItemArray
,
1250 static HRESULT WINAPI
NSTC2_fnGetItemCustomState(INameSpaceTreeControl2
* iface
,
1254 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1255 FIXME("stub, %p (%p, %p)\n", This
, psi
, piStateNumber
);
1259 static HRESULT WINAPI
NSTC2_fnSetItemCustomState(INameSpaceTreeControl2
* iface
,
1263 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1264 FIXME("stub, %p (%p, %d)\n", This
, psi
, iStateNumber
);
1268 static HRESULT WINAPI
NSTC2_fnEnsureItemVisible(INameSpaceTreeControl2
* iface
,
1271 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1274 TRACE("%p (%p)\n", This
, psi
);
1276 hitem
= treeitem_from_shellitem(This
, psi
);
1279 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (WPARAM
)hitem
);
1283 return E_INVALIDARG
;
1286 static HRESULT WINAPI
NSTC2_fnSetTheme(INameSpaceTreeControl2
* iface
,
1289 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1290 FIXME("stub, %p (%p)\n", This
, pszTheme
);
1294 static HRESULT WINAPI
NSTC2_fnGetNextItem(INameSpaceTreeControl2
* iface
,
1297 IShellItem
**ppsiNext
)
1299 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1300 HTREEITEM hitem
, hnext
;
1302 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcgi
, ppsiNext
);
1304 if(!ppsiNext
) return E_POINTER
;
1305 if(!psi
) return E_FAIL
;
1309 hitem
= treeitem_from_shellitem(This
, psi
);
1311 return E_INVALIDARG
;
1315 case NSTCGNI_NEXT
: tvgn
= TVGN_NEXT
; break;
1316 case NSTCGNI_NEXTVISIBLE
: tvgn
= TVGN_NEXTVISIBLE
; break;
1317 case NSTCGNI_PREV
: tvgn
= TVGN_PREVIOUS
; break;
1318 case NSTCGNI_PREVVISIBLE
: tvgn
= TVGN_PREVIOUSVISIBLE
; break;
1319 case NSTCGNI_PARENT
: tvgn
= TVGN_PARENT
; break;
1320 case NSTCGNI_CHILD
: tvgn
= TVGN_CHILD
; break;
1321 case NSTCGNI_FIRSTVISIBLE
: tvgn
= TVGN_FIRSTVISIBLE
; break;
1322 case NSTCGNI_LASTVISIBLE
: tvgn
= TVGN_LASTVISIBLE
; break;
1324 FIXME("Unknown nstcgi value %d\n", nstcgi
);
1328 hnext
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, tvgn
, (WPARAM
)hitem
);
1331 *ppsiNext
= shellitem_from_treeitem(This
, hnext
);
1332 IShellItem_AddRef(*ppsiNext
);
1339 static HRESULT WINAPI
NSTC2_fnHitTest(INameSpaceTreeControl2
* iface
,
1341 IShellItem
**ppsiOut
)
1343 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1345 TRACE("%p (%p, %p)\n", This
, ppsiOut
, ppt
);
1347 if(!ppt
|| !ppsiOut
)
1352 hitem
= treeitem_from_point(This
, ppt
, NULL
);
1354 *ppsiOut
= shellitem_from_treeitem(This
, hitem
);
1358 IShellItem_AddRef(*ppsiOut
);
1365 static HRESULT WINAPI
NSTC2_fnGetItemRect(INameSpaceTreeControl2
* iface
,
1369 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1371 TRACE("%p (%p, %p)\n", This
, psi
, prect
);
1376 hitem
= treeitem_from_shellitem(This
, psi
);
1379 *(HTREEITEM
*)prect
= hitem
;
1380 if(SendMessageW(This
->hwnd_tv
, TVM_GETITEMRECT
, FALSE
, (LPARAM
)prect
))
1382 MapWindowPoints(This
->hwnd_tv
, HWND_DESKTOP
, (POINT
*)prect
, 2);
1387 return E_INVALIDARG
;
1390 static HRESULT WINAPI
NSTC2_fnCollapseAll(INameSpaceTreeControl2
* iface
)
1392 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1394 TRACE("%p\n", This
);
1396 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1397 collapse_all(This
, root
->htreeitem
);
1402 static HRESULT WINAPI
NSTC2_fnSetControlStyle(INameSpaceTreeControl2
* iface
,
1403 NSTCSTYLE nstcsMask
,
1404 NSTCSTYLE nstcsStyle
)
1406 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1407 static const DWORD tv_style_flags
=
1408 NSTCS_HASEXPANDOS
| NSTCS_HASLINES
| NSTCS_FULLROWSELECT
|
1409 NSTCS_HORIZONTALSCROLL
| NSTCS_ROOTHASEXPANDO
|
1410 NSTCS_SHOWSELECTIONALWAYS
| NSTCS_NOINFOTIP
| NSTCS_EVENHEIGHT
|
1411 NSTCS_DISABLEDRAGDROP
| NSTCS_NOEDITLABELS
| NSTCS_CHECKBOXES
;
1412 static const DWORD host_style_flags
= NSTCS_TABSTOP
| NSTCS_BORDER
;
1413 static const DWORD nstc_flags
=
1414 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
|
1415 NSTCS_FAVORITESMODE
| NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
|
1416 NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
| NSTCS_SHOWREFRESHBUTTON
;
1417 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1419 /* Fail if there is an attempt to set an unknown style. */
1420 if(nstcsMask
& ~(tv_style_flags
| host_style_flags
| nstc_flags
))
1423 if(nstcsMask
& tv_style_flags
)
1426 treeview_style_from_nstcs(This
, nstcsStyle
, nstcsMask
, &new_style
);
1427 SetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
, new_style
);
1430 /* Flags affecting the host window */
1431 if(nstcsMask
& NSTCS_BORDER
)
1433 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
);
1434 new_style
&= ~WS_BORDER
;
1435 new_style
|= nstcsStyle
& NSTCS_BORDER
? WS_BORDER
: 0;
1436 SetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
, new_style
);
1438 if(nstcsMask
& NSTCS_TABSTOP
)
1440 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
);
1441 new_style
&= ~WS_EX_CONTROLPARENT
;
1442 new_style
|= nstcsStyle
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
1443 SetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
, new_style
);
1446 if((nstcsStyle
& nstcsMask
) & unsupported_styles
)
1447 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1448 (nstcsStyle
& nstcsMask
),
1449 (nstcsStyle
& nstcsMask
) & unsupported_styles
);
1451 This
->style
&= ~nstcsMask
;
1452 This
->style
|= (nstcsStyle
& nstcsMask
);
1457 static HRESULT WINAPI
NSTC2_fnGetControlStyle(INameSpaceTreeControl2
* iface
,
1458 NSTCSTYLE nstcsMask
,
1459 NSTCSTYLE
*pnstcsStyle
)
1461 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1462 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1464 *pnstcsStyle
= (This
->style
& nstcsMask
);
1469 static HRESULT WINAPI
NSTC2_fnSetControlStyle2(INameSpaceTreeControl2
* iface
,
1470 NSTCSTYLE2 nstcsMask
,
1471 NSTCSTYLE2 nstcsStyle
)
1473 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1474 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1476 if((nstcsStyle
& nstcsMask
) & unsupported_styles2
)
1477 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1478 (nstcsStyle
& nstcsMask
),
1479 (nstcsStyle
& nstcsMask
) & unsupported_styles2
);
1481 This
->style2
&= ~nstcsMask
;
1482 This
->style2
|= (nstcsStyle
& nstcsMask
);
1487 static HRESULT WINAPI
NSTC2_fnGetControlStyle2(INameSpaceTreeControl2
* iface
,
1488 NSTCSTYLE2 nstcsMask
,
1489 NSTCSTYLE2
*pnstcsStyle
)
1491 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1492 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1494 *pnstcsStyle
= (This
->style2
& nstcsMask
);
1499 static const INameSpaceTreeControl2Vtbl vt_INameSpaceTreeControl2
= {
1500 NSTC2_fnQueryInterface
,
1505 NSTC2_fnTreeUnadvise
,
1509 NSTC2_fnRemoveAllRoots
,
1510 NSTC2_fnGetRootItems
,
1511 NSTC2_fnSetItemState
,
1512 NSTC2_fnGetItemState
,
1513 NSTC2_fnGetSelectedItems
,
1514 NSTC2_fnGetItemCustomState
,
1515 NSTC2_fnSetItemCustomState
,
1516 NSTC2_fnEnsureItemVisible
,
1518 NSTC2_fnGetNextItem
,
1520 NSTC2_fnGetItemRect
,
1521 NSTC2_fnCollapseAll
,
1522 NSTC2_fnSetControlStyle
,
1523 NSTC2_fnGetControlStyle
,
1524 NSTC2_fnSetControlStyle2
,
1525 NSTC2_fnGetControlStyle2
1528 /**************************************************************************
1529 * IOleWindow Implementation
1532 static HRESULT WINAPI
IOW_fnQueryInterface(IOleWindow
*iface
, REFIID riid
, void **ppvObject
)
1534 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1535 TRACE("%p\n", This
);
1536 return NSTC2_fnQueryInterface(&This
->INameSpaceTreeControl2_iface
, riid
, ppvObject
);
1539 static ULONG WINAPI
IOW_fnAddRef(IOleWindow
*iface
)
1541 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1542 TRACE("%p\n", This
);
1543 return NSTC2_fnAddRef(&This
->INameSpaceTreeControl2_iface
);
1546 static ULONG WINAPI
IOW_fnRelease(IOleWindow
*iface
)
1548 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1549 TRACE("%p\n", This
);
1550 return NSTC2_fnRelease(&This
->INameSpaceTreeControl2_iface
);
1553 static HRESULT WINAPI
IOW_fnGetWindow(IOleWindow
*iface
, HWND
*phwnd
)
1555 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1556 TRACE("%p (%p)\n", This
, phwnd
);
1558 *phwnd
= This
->hwnd_main
;
1562 static HRESULT WINAPI
IOW_fnContextSensitiveHelp(IOleWindow
*iface
, BOOL fEnterMode
)
1564 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1565 TRACE("%p (%d)\n", This
, fEnterMode
);
1567 /* Not implemented */
1571 static const IOleWindowVtbl vt_IOleWindow
= {
1572 IOW_fnQueryInterface
,
1576 IOW_fnContextSensitiveHelp
1579 HRESULT
NamespaceTreeControl_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
1584 TRACE ("%p %s %p\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
1589 return CLASS_E_NOAGGREGATION
;
1591 EFRAME_LockModule();
1593 nstc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(NSTC2Impl
));
1595 nstc
->INameSpaceTreeControl2_iface
.lpVtbl
= &vt_INameSpaceTreeControl2
;
1596 nstc
->IOleWindow_iface
.lpVtbl
= &vt_IOleWindow
;
1598 list_init(&nstc
->roots
);
1600 ret
= INameSpaceTreeControl2_QueryInterface(&nstc
->INameSpaceTreeControl2_iface
, riid
, ppv
);
1601 INameSpaceTreeControl2_Release(&nstc
->INameSpaceTreeControl2_iface
);
1603 TRACE("--(%p)\n", ppv
);