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 "commoncontrols.h"
34 #include "wine/list.h"
35 #include "wine/debug.h"
37 #include "explorerframe_main.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(nstc
);
41 typedef struct nstc_root
{
45 NSTCROOTSTYLE root_style
;
46 IShellItemFilter
*pif
;
51 INameSpaceTreeControl2 INameSpaceTreeControl2_iface
;
52 IOleWindow IOleWindow_iface
;
58 WNDPROC tv_oldwndproc
;
64 INameSpaceTreeControlCustomDraw
*customdraw
;
65 INameSpaceTreeControlDropHandler
*dragdrop
;
66 INameSpaceTreeControlEvents
*events
;
69 static const DWORD unsupported_styles
=
70 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
| NSTCS_FAVORITESMODE
|
71 NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
| NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
|
72 NSTCS_SHOWREFRESHBUTTON
| NSTCS_SPRINGEXPAND
| NSTCS_RICHTOOLTIP
| NSTCS_NOINDENTCHECKS
;
73 static const DWORD unsupported_styles2
=
74 NSTCS2_INTERRUPTNOTIFICATIONS
| NSTCS2_SHOWNULLSPACEMENU
| NSTCS2_DISPLAYPADDING
|
75 NSTCS2_DISPLAYPINNEDONLY
| NTSCS2_NOSINGLETONAUTOEXPAND
| NTSCS2_NEVERINSERTNONENUMERATED
;
77 static const WCHAR thispropW
[] = {'P','R','O','P','_','T','H','I','S',0};
79 static inline NSTC2Impl
*impl_from_INameSpaceTreeControl2(INameSpaceTreeControl2
*iface
)
81 return CONTAINING_RECORD(iface
, NSTC2Impl
, INameSpaceTreeControl2_iface
);
84 static inline NSTC2Impl
*impl_from_IOleWindow(IOleWindow
*iface
)
86 return CONTAINING_RECORD(iface
, NSTC2Impl
, IOleWindow_iface
);
89 /* Forward declarations */
90 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
);
92 /*************************************************************************
93 * NamespaceTree event wrappers
95 static HRESULT
events_OnGetDefaultIconIndex(NSTC2Impl
*This
, IShellItem
*psi
,
96 int *piDefaultIcon
, int *piOpenIcon
)
100 if(!This
->events
) return E_NOTIMPL
;
102 refcount
= IShellItem_AddRef(psi
);
103 ret
= INameSpaceTreeControlEvents_OnGetDefaultIconIndex(This
->events
, psi
, piDefaultIcon
, piOpenIcon
);
104 if(IShellItem_Release(psi
) < refcount
- 1)
105 ERR("ShellItem was released by client - please file a bug.\n");
109 static HRESULT
events_OnItemAdded(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
113 if(!This
->events
) return S_OK
;
115 refcount
= IShellItem_AddRef(psi
);
116 ret
= INameSpaceTreeControlEvents_OnItemAdded(This
->events
, psi
, fIsRoot
);
117 if(IShellItem_Release(psi
) < refcount
- 1)
118 ERR("ShellItem was released by client - please file a bug.\n");
122 static HRESULT
events_OnItemDeleted(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
126 if(!This
->events
) return S_OK
;
128 refcount
= IShellItem_AddRef(psi
);
129 ret
= INameSpaceTreeControlEvents_OnItemDeleted(This
->events
, psi
, fIsRoot
);
130 if(IShellItem_Release(psi
) < refcount
- 1)
131 ERR("ShellItem was released by client - please file a bug.\n");
135 static HRESULT
events_OnBeforeExpand(NSTC2Impl
*This
, IShellItem
*psi
)
139 if(!This
->events
) return S_OK
;
141 refcount
= IShellItem_AddRef(psi
);
142 ret
= INameSpaceTreeControlEvents_OnBeforeExpand(This
->events
, psi
);
143 if(IShellItem_Release(psi
) < refcount
- 1)
144 ERR("ShellItem was released by client - please file a bug.\n");
148 static HRESULT
events_OnAfterExpand(NSTC2Impl
*This
, IShellItem
*psi
)
152 if(!This
->events
) return S_OK
;
154 refcount
= IShellItem_AddRef(psi
);
155 ret
= INameSpaceTreeControlEvents_OnAfterExpand(This
->events
, psi
);
156 if(IShellItem_Release(psi
) < refcount
- 1)
157 ERR("ShellItem was released by client - please file a bug.\n");
161 static HRESULT
events_OnItemClick(NSTC2Impl
*This
, IShellItem
*psi
,
162 NSTCEHITTEST nstceHitTest
, NSTCECLICKTYPE nstceClickType
)
166 if(!This
->events
) return S_OK
;
168 refcount
= IShellItem_AddRef(psi
);
169 ret
= INameSpaceTreeControlEvents_OnItemClick(This
->events
, psi
, nstceHitTest
, nstceClickType
);
170 if(IShellItem_Release(psi
) < refcount
- 1)
171 ERR("ShellItem was released by client - please file a bug.\n");
175 static HRESULT
events_OnSelectionChanged(NSTC2Impl
*This
, IShellItemArray
*psia
)
177 if(!This
->events
) return S_OK
;
179 return INameSpaceTreeControlEvents_OnSelectionChanged(This
->events
, psia
);
182 static HRESULT
events_OnKeyboardInput(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
184 if(!This
->events
) return S_OK
;
186 return INameSpaceTreeControlEvents_OnKeyboardInput(This
->events
, uMsg
, wParam
, lParam
);
189 /*************************************************************************
190 * NamespaceTree helper functions
192 static DWORD
treeview_style_from_nstcs(NSTC2Impl
*This
, NSTCSTYLE nstcs
,
193 NSTCSTYLE nstcs_mask
, DWORD
*new_style
)
195 DWORD old_style
, tv_mask
= 0;
196 TRACE("%p, %x, %x, %p\n", This
, nstcs
, nstcs_mask
, new_style
);
199 old_style
= GetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
);
201 old_style
= /* The default */
202 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
|
203 WS_TABSTOP
| TVS_NOHSCROLL
| TVS_NONEVENHEIGHT
| TVS_INFOTIP
|
204 TVS_EDITLABELS
| TVS_TRACKSELECT
;
206 if(nstcs_mask
& NSTCS_HASEXPANDOS
) tv_mask
|= TVS_HASBUTTONS
;
207 if(nstcs_mask
& NSTCS_HASLINES
) tv_mask
|= TVS_HASLINES
;
208 if(nstcs_mask
& NSTCS_FULLROWSELECT
) tv_mask
|= TVS_FULLROWSELECT
;
209 if(nstcs_mask
& NSTCS_HORIZONTALSCROLL
) tv_mask
|= TVS_NOHSCROLL
;
210 if(nstcs_mask
& NSTCS_ROOTHASEXPANDO
) tv_mask
|= TVS_LINESATROOT
;
211 if(nstcs_mask
& NSTCS_SHOWSELECTIONALWAYS
) tv_mask
|= TVS_SHOWSELALWAYS
;
212 if(nstcs_mask
& NSTCS_NOINFOTIP
) tv_mask
|= TVS_INFOTIP
;
213 if(nstcs_mask
& NSTCS_EVENHEIGHT
) tv_mask
|= TVS_NONEVENHEIGHT
;
214 if(nstcs_mask
& NSTCS_DISABLEDRAGDROP
) tv_mask
|= TVS_DISABLEDRAGDROP
;
215 if(nstcs_mask
& NSTCS_NOEDITLABELS
) tv_mask
|= TVS_EDITLABELS
;
216 if(nstcs_mask
& NSTCS_CHECKBOXES
) tv_mask
|= TVS_CHECKBOXES
;
220 if(nstcs
& NSTCS_HASEXPANDOS
) *new_style
|= TVS_HASBUTTONS
;
221 if(nstcs
& NSTCS_HASLINES
) *new_style
|= TVS_HASLINES
;
222 if(nstcs
& NSTCS_FULLROWSELECT
) *new_style
|= TVS_FULLROWSELECT
;
223 if(!(nstcs
& NSTCS_HORIZONTALSCROLL
)) *new_style
|= TVS_NOHSCROLL
;
224 if(nstcs
& NSTCS_ROOTHASEXPANDO
) *new_style
|= TVS_LINESATROOT
;
225 if(nstcs
& NSTCS_SHOWSELECTIONALWAYS
) *new_style
|= TVS_SHOWSELALWAYS
;
226 if(!(nstcs
& NSTCS_NOINFOTIP
)) *new_style
|= TVS_INFOTIP
;
227 if(!(nstcs
& NSTCS_EVENHEIGHT
)) *new_style
|= TVS_NONEVENHEIGHT
;
228 if(nstcs
& NSTCS_DISABLEDRAGDROP
) *new_style
|= TVS_DISABLEDRAGDROP
;
229 if(!(nstcs
& NSTCS_NOEDITLABELS
)) *new_style
|= TVS_EDITLABELS
;
230 if(nstcs
& NSTCS_CHECKBOXES
) *new_style
|= TVS_CHECKBOXES
;
232 *new_style
= (old_style
& ~tv_mask
) | (*new_style
& tv_mask
);
234 TRACE("old: %08x, new: %08x\n", old_style
, *new_style
);
236 return old_style
^*new_style
;
239 static IShellItem
*shellitem_from_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
243 tvi
.mask
= TVIF_PARAM
;
247 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
249 TRACE("ShellItem: %p\n", (void*)tvi
.lParam
);
250 return (IShellItem
*)tvi
.lParam
;
253 /* Returns the root that the given treeitem belongs to. */
254 static nstc_root
*root_for_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
256 HTREEITEM tmp
, hroot
= hitem
;
259 /* Work our way up the hierarchy */
260 for(tmp
= hitem
; tmp
!= NULL
; hroot
= tmp
?tmp
:hroot
)
261 tmp
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)hroot
);
263 /* Search through the list of roots for a match */
264 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
265 if(root
->htreeitem
== hroot
)
268 TRACE("root is %p\n", root
);
272 /* Find a shellitem in the tree, starting from the given node. */
273 static HTREEITEM
search_for_shellitem(NSTC2Impl
*This
, HTREEITEM node
,
276 IShellItem
*psi_node
;
277 HTREEITEM next
, result
= NULL
;
280 TRACE("%p, %p, %p\n", This
, node
, psi
);
282 /* Check this node */
283 psi_node
= shellitem_from_treeitem(This
, node
);
284 hr
= IShellItem_Compare(psi
, psi_node
, SICHINT_DISPLAY
, &cmpo
);
289 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
290 TVGN_CHILD
, (LPARAM
)node
);
293 result
= search_for_shellitem(This
, next
, psi
);
294 if(result
) return result
;
297 /* Try our next sibling. */
298 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
299 TVGN_NEXT
, (LPARAM
)node
);
301 result
= search_for_shellitem(This
, next
, psi
);
306 static HTREEITEM
treeitem_from_shellitem(NSTC2Impl
*This
, IShellItem
*psi
)
309 TRACE("%p, %p\n", This
, psi
);
311 root
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
316 return search_for_shellitem(This
, root
, psi
);
319 static int get_icon(LPCITEMIDLIST lpi
, UINT extra_flags
)
322 UINT flags
= SHGFI_PIDL
| SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
;
325 list
= (IImageList
*)SHGetFileInfoW((LPCWSTR
)lpi
, 0 ,&sfi
, sizeof(SHFILEINFOW
), flags
| extra_flags
);
326 if (list
) IImageList_Release(list
);
330 /* Insert a shellitem into the given place in the tree and return the
331 resulting treeitem. */
332 static HTREEITEM
insert_shellitem(NSTC2Impl
*This
, IShellItem
*psi
,
333 HTREEITEM hParent
, HTREEITEM hInsertAfter
)
335 TVINSERTSTRUCTW tvins
;
336 TVITEMEXW
*tvi
= &tvins
.u
.itemex
;
338 TRACE("%p (%p, %p)\n", psi
, hParent
, hInsertAfter
);
340 tvi
->mask
= TVIF_PARAM
| TVIF_CHILDREN
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_TEXT
;
341 tvi
->cChildren
= I_CHILDRENCALLBACK
;
342 tvi
->iImage
= tvi
->iSelectedImage
= I_IMAGECALLBACK
;
343 tvi
->pszText
= LPSTR_TEXTCALLBACKW
;
345 /* Every treeitem contains a pointer to the corresponding ShellItem. */
346 tvi
->lParam
= (LPARAM
)psi
;
347 tvins
.hParent
= hParent
;
348 tvins
.hInsertAfter
= hInsertAfter
;
350 hinserted
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_INSERTITEMW
, 0,
351 (LPARAM
)(LPTVINSERTSTRUCTW
)&tvins
);
353 IShellItem_AddRef(psi
);
358 /* Enumerates the children of the folder represented by hitem
359 * according to the settings for the root, and adds them to the
360 * treeview. Returns the number of children added. */
361 static UINT
fill_sublevel(NSTC2Impl
*This
, HTREEITEM hitem
)
363 IShellItem
*psiParent
= shellitem_from_treeitem(This
, hitem
);
364 nstc_root
*root
= root_for_treeitem(This
, hitem
);
365 LPITEMIDLIST pidl_parent
;
371 hr
= SHGetIDListFromObject((IUnknown
*)psiParent
, &pidl_parent
);
374 hr
= IShellItem_BindToHandler(psiParent
, NULL
, &BHID_SFObject
, &IID_IShellFolder
, (void**)&psf
);
377 hr
= IShellFolder_EnumObjects(psf
, NULL
, root
->enum_flags
, &peidl
);
384 while( S_OK
== IEnumIDList_Next(peidl
, 1, &pidl
, &fetched
) )
386 hr
= SHCreateShellItem(NULL
, psf
, pidl
, &psi
);
390 if(insert_shellitem(This
, psi
, hitem
, NULL
))
392 events_OnItemAdded(This
, psi
, FALSE
);
396 IShellItem_Release(psi
);
399 ERR("SHCreateShellItem failed with 0x%08x\n", hr
);
401 IEnumIDList_Release(peidl
);
404 ERR("EnumObjects failed with 0x%08x\n", hr
);
406 IShellFolder_Release(psf
);
409 ERR("BindToHandler failed with 0x%08x\n", hr
);
414 ERR("SHGetIDListFromObject failed with 0x%08x\n", hr
);
419 static HTREEITEM
get_selected_treeitem(NSTC2Impl
*This
)
421 return (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
424 static IShellItem
*get_selected_shellitem(NSTC2Impl
*This
)
426 return shellitem_from_treeitem(This
, get_selected_treeitem(This
));
429 static void collapse_all(NSTC2Impl
*This
, HTREEITEM node
)
433 /* Collapse this node first, and then first child/next sibling. */
434 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_COLLAPSE
, (LPARAM
)node
);
436 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
437 if(next
) collapse_all(This
, next
);
439 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_NEXT
, (LPARAM
)node
);
440 if(next
) collapse_all(This
, next
);
443 static HTREEITEM
treeitem_from_point(NSTC2Impl
*This
, const POINT
*pt
, UINT
*hitflag
)
450 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tviht
);
451 if(hitflag
) *hitflag
= tviht
.flags
;
455 /*************************************************************************
456 * NamespaceTree window functions
458 static LRESULT
create_namespacetree(HWND hWnd
, CREATESTRUCTW
*crs
)
460 NSTC2Impl
*This
= crs
->lpCreateParams
;
461 HIMAGELIST ShellSmallIconList
;
462 DWORD treeview_style
, treeview_ex_style
;
464 TRACE("%p (%p)\n", This
, crs
);
465 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (LPARAM
)This
);
466 This
->hwnd_main
= hWnd
;
468 treeview_style_from_nstcs(This
, This
->style
, 0xFFFFFFFF, &treeview_style
);
470 This
->hwnd_tv
= CreateWindowExW(0, WC_TREEVIEWW
, NULL
, treeview_style
,
471 0, 0, crs
->cx
, crs
->cy
,
472 hWnd
, NULL
, explorerframe_hinstance
, NULL
);
476 ERR("Failed to create treeview!\n");
477 return HRESULT_FROM_WIN32(GetLastError());
480 treeview_ex_style
= TVS_EX_DRAWIMAGEASYNC
| TVS_EX_RICHTOOLTIP
|
481 TVS_EX_DOUBLEBUFFER
| TVS_EX_NOSINGLECOLLAPSE
;
483 if(This
->style
& NSTCS_AUTOHSCROLL
)
484 treeview_ex_style
|= TVS_EX_AUTOHSCROLL
;
485 if(This
->style
& NSTCS_FADEINOUTEXPANDOS
)
486 treeview_ex_style
|= TVS_EX_FADEINOUTEXPANDOS
;
487 if(This
->style
& NSTCS_PARTIALCHECKBOXES
)
488 treeview_ex_style
|= TVS_EX_PARTIALCHECKBOXES
;
489 if(This
->style
& NSTCS_EXCLUSIONCHECKBOXES
)
490 treeview_ex_style
|= TVS_EX_EXCLUSIONCHECKBOXES
;
491 if(This
->style
& NSTCS_DIMMEDCHECKBOXES
)
492 treeview_ex_style
|= TVS_EX_DIMMEDCHECKBOXES
;
494 SendMessageW(This
->hwnd_tv
, TVM_SETEXTENDEDSTYLE
, treeview_ex_style
, 0xffff);
496 if(Shell_GetImageLists(NULL
, &ShellSmallIconList
))
498 SendMessageW(This
->hwnd_tv
, TVM_SETIMAGELIST
,
499 (WPARAM
)TVSIL_NORMAL
, (LPARAM
)ShellSmallIconList
);
503 ERR("Failed to get the System Image List.\n");
506 INameSpaceTreeControl2_AddRef(&This
->INameSpaceTreeControl2_iface
);
508 /* Subclass the treeview to get the keyboard events. */
509 This
->tv_oldwndproc
= (WNDPROC
)SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
,
510 (ULONG_PTR
)tv_wndproc
);
511 if(This
->tv_oldwndproc
)
512 SetPropW(This
->hwnd_tv
, thispropW
, This
);
517 static LRESULT
resize_namespacetree(NSTC2Impl
*This
)
522 GetClientRect(This
->hwnd_main
, &rc
);
523 MoveWindow(This
->hwnd_tv
, 0, 0, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, TRUE
);
528 static LRESULT
destroy_namespacetree(NSTC2Impl
*This
)
532 /* Undo the subclassing */
533 if(This
->tv_oldwndproc
)
535 SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
, (ULONG_PTR
)This
->tv_oldwndproc
);
536 RemovePropW(This
->hwnd_tv
, thispropW
);
539 INameSpaceTreeControl2_RemoveAllRoots(&This
->INameSpaceTreeControl2_iface
);
541 /* This reference was added in create_namespacetree */
542 INameSpaceTreeControl2_Release(&This
->INameSpaceTreeControl2_iface
);
546 static LRESULT
on_tvn_deleteitemw(NSTC2Impl
*This
, LPARAM lParam
)
548 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
551 IShellItem_Release((IShellItem
*)nmtv
->itemOld
.lParam
);
555 static LRESULT
on_tvn_getdispinfow(NSTC2Impl
*This
, LPARAM lParam
)
557 NMTVDISPINFOW
*dispinfo
= (NMTVDISPINFOW
*)lParam
;
558 TVITEMEXW
*item
= (TVITEMEXW
*)&dispinfo
->item
;
559 IShellItem
*psi
= shellitem_from_treeitem(This
, item
->hItem
);
562 TRACE("%p, %p (mask: %x)\n", This
, dispinfo
, item
->mask
);
564 if(item
->mask
& TVIF_CHILDREN
)
568 hr
= IShellItem_GetAttributes(psi
, SFGAO_HASSUBFOLDER
, &sfgao
);
570 item
->cChildren
= (sfgao
& SFGAO_HASSUBFOLDER
)?1:0;
574 item
->mask
|= TVIF_DI_SETITEM
;
577 if(item
->mask
& (TVIF_IMAGE
|TVIF_SELECTEDIMAGE
))
581 hr
= events_OnGetDefaultIconIndex(This
, psi
, &item
->iImage
, &item
->iSelectedImage
);
584 hr
= SHGetIDListFromObject((IUnknown
*)psi
, &pidl
);
587 item
->iImage
= item
->iSelectedImage
= get_icon(pidl
, 0);
588 item
->mask
|= TVIF_DI_SETITEM
;
592 ERR("Failed to get IDList (%08x).\n", hr
);
596 if(item
->mask
& TVIF_TEXT
)
600 hr
= IShellItem_GetDisplayName(psi
, SIGDN_NORMALDISPLAY
, &display_name
);
603 lstrcpynW(item
->pszText
, display_name
, MAX_PATH
);
604 item
->mask
|= TVIF_DI_SETITEM
;
605 CoTaskMemFree(display_name
);
608 ERR("Failed to get display name (%08x).\n", hr
);
614 static BOOL
treenode_has_subfolders(NSTC2Impl
*This
, HTREEITEM node
)
616 return SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
619 static LRESULT
on_tvn_itemexpandingw(NSTC2Impl
*This
, LPARAM lParam
)
621 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
625 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
626 events_OnBeforeExpand(This
, psi
);
628 if(!treenode_has_subfolders(This
, nmtv
->itemNew
.hItem
))
630 /* The node has no children, try to find some */
631 if(!fill_sublevel(This
, nmtv
->itemNew
.hItem
))
634 /* Failed to enumerate any children, remove the expando
636 tvi
.hItem
= nmtv
->itemNew
.hItem
;
637 tvi
.mask
= TVIF_CHILDREN
;
639 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
647 static LRESULT
on_tvn_itemexpandedw(NSTC2Impl
*This
, LPARAM lParam
)
649 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
653 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
654 events_OnAfterExpand(This
, psi
);
658 static LRESULT
on_tvn_selchangedw(NSTC2Impl
*This
, LPARAM lParam
)
660 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
661 IShellItemArray
*psia
;
666 /* Note: Only supports one selected item. */
667 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
668 hr
= SHCreateShellItemArrayFromShellItem(psi
, &IID_IShellItemArray
, (void**)&psia
);
671 events_OnSelectionChanged(This
, psia
);
672 IShellItemArray_Release(psia
);
678 static LRESULT
on_nm_click(NSTC2Impl
*This
, NMHDR
*nmhdr
)
683 TRACE("%p (%p)\n", This
, nmhdr
);
685 GetCursorPos(&tvhit
.pt
);
686 ScreenToClient(This
->hwnd_tv
, &tvhit
.pt
);
687 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
689 if(tvhit
.flags
& (TVHT_NOWHERE
|TVHT_ABOVE
|TVHT_BELOW
))
692 /* TVHT_ maps onto the corresponding NSTCEHT_ */
693 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
694 hr
= events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_LBUTTON
);
696 /* The expando should not be expanded unless
698 if(tvhit
.flags
== TVHT_ONITEMBUTTON
)
707 static LRESULT
on_wm_mbuttonup(NSTC2Impl
*This
, WPARAM wParam
, LPARAM lParam
)
712 TRACE("%p (%lx, %lx)\n", This
, wParam
, lParam
);
714 tvhit
.pt
.x
= (int)(short)LOWORD(lParam
);
715 tvhit
.pt
.y
= (int)(short)HIWORD(lParam
);
717 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
719 /* Seems to generate only ONITEM and ONITEMICON */
720 if( !(tvhit
.flags
& (TVHT_ONITEM
|TVHT_ONITEMICON
)) )
723 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
724 hr
= events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_MBUTTON
);
732 static LRESULT
on_kbd_event(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
736 TRACE("%p : %d, %lx, %lx\n", This
, uMsg
, wParam
, lParam
);
738 /* Handled by the client? */
739 if(FAILED(events_OnKeyboardInput(This
, uMsg
, wParam
, lParam
)))
742 if(uMsg
== WM_KEYDOWN
)
747 psi
= get_selected_shellitem(This
);
748 FIXME("Deletion of file requested (shellitem: %p).\n", psi
);
752 hitem
= get_selected_treeitem(This
);
753 SendMessageW(This
->hwnd_tv
, TVM_EDITLABELW
, 0, (LPARAM
)hitem
);
758 /* Let the TreeView handle the key */
762 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
)
764 NSTC2Impl
*This
= (NSTC2Impl
*)GetPropW(hWnd
, thispropW
);
773 if(on_kbd_event(This
, uMessage
, wParam
, lParam
))
777 case WM_MBUTTONUP
: return on_wm_mbuttonup(This
, wParam
, lParam
);
780 /* Pass the message on to the treeview */
781 return CallWindowProcW(This
->tv_oldwndproc
, hWnd
, uMessage
, wParam
, lParam
);
784 static LRESULT CALLBACK
NSTC2_WndProc(HWND hWnd
, UINT uMessage
,
785 WPARAM wParam
, LPARAM lParam
)
787 NSTC2Impl
*This
= (NSTC2Impl
*)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
792 case WM_NCCREATE
: return create_namespacetree(hWnd
, (CREATESTRUCTW
*)lParam
);
793 case WM_SIZE
: return resize_namespacetree(This
);
794 case WM_DESTROY
: return destroy_namespacetree(This
);
796 nmhdr
= (NMHDR
*)lParam
;
799 case NM_CLICK
: return on_nm_click(This
, nmhdr
);
800 case TVN_DELETEITEMW
: return on_tvn_deleteitemw(This
, lParam
);
801 case TVN_GETDISPINFOW
: return on_tvn_getdispinfow(This
, lParam
);
802 case TVN_ITEMEXPANDINGW
: return on_tvn_itemexpandingw(This
, lParam
);
803 case TVN_ITEMEXPANDEDW
: return on_tvn_itemexpandedw(This
, lParam
);
804 case TVN_SELCHANGEDW
: return on_tvn_selchangedw(This
, lParam
);
808 default: return DefWindowProcW(hWnd
, uMessage
, wParam
, lParam
);
813 /**************************************************************************
814 * INameSpaceTreeControl2 Implementation
816 static HRESULT WINAPI
NSTC2_fnQueryInterface(INameSpaceTreeControl2
* iface
,
820 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
821 TRACE("%p (%s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
824 if(IsEqualIID(riid
, &IID_INameSpaceTreeControl2
) ||
825 IsEqualIID(riid
, &IID_INameSpaceTreeControl
) ||
826 IsEqualIID(riid
, &IID_IUnknown
))
828 *ppvObject
= &This
->INameSpaceTreeControl2_iface
;
830 else if(IsEqualIID(riid
, &IID_IOleWindow
))
832 *ppvObject
= &This
->IOleWindow_iface
;
837 IUnknown_AddRef((IUnknown
*)*ppvObject
);
841 return E_NOINTERFACE
;
844 static ULONG WINAPI
NSTC2_fnAddRef(INameSpaceTreeControl2
* iface
)
846 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
847 LONG ref
= InterlockedIncrement(&This
->ref
);
849 TRACE("%p - ref %d\n", This
, ref
);
854 static ULONG WINAPI
NSTC2_fnRelease(INameSpaceTreeControl2
* iface
)
856 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
857 LONG ref
= InterlockedDecrement(&This
->ref
);
859 TRACE("%p - ref: %d\n", This
, ref
);
864 HeapFree(GetProcessHeap(), 0, This
);
865 EFRAME_UnlockModule();
872 static HRESULT WINAPI
NSTC2_fnInitialize(INameSpaceTreeControl2
* iface
,
875 NSTCSTYLE nstcsFlags
)
877 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
879 DWORD window_style
, window_ex_style
;
880 INITCOMMONCONTROLSEX icex
;
882 static const WCHAR NSTC2_CLASS_NAME
[] =
883 {'N','a','m','e','s','p','a','c','e','T','r','e','e',
884 'C','o','n','t','r','o','l',0};
886 TRACE("%p (%p, %p, %x)\n", This
, hwndParent
, prc
, nstcsFlags
);
888 if(nstcsFlags
& unsupported_styles
)
889 FIXME("0x%08x contains the unsupported style(s) 0x%08x\n",
890 nstcsFlags
, nstcsFlags
& unsupported_styles
);
892 This
->style
= nstcsFlags
;
894 icex
.dwSize
= sizeof( icex
);
895 icex
.dwICC
= ICC_TREEVIEW_CLASSES
;
896 InitCommonControlsEx( &icex
);
898 if(!GetClassInfoW(explorerframe_hinstance
, NSTC2_CLASS_NAME
, &wc
))
900 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
901 wc
.lpfnWndProc
= NSTC2_WndProc
;
904 wc
.hInstance
= explorerframe_hinstance
;
906 wc
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
907 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
908 wc
.lpszMenuName
= NULL
;
909 wc
.lpszClassName
= NSTC2_CLASS_NAME
;
911 if (!RegisterClassW(&wc
)) return E_FAIL
;
914 /* NSTCS_TABSTOP and NSTCS_BORDER affects the host window */
915 window_style
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
|
916 (nstcsFlags
& NSTCS_BORDER
? WS_BORDER
: 0);
917 window_ex_style
= nstcsFlags
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
924 This
->hwnd_main
= CreateWindowExW(window_ex_style
, NSTC2_CLASS_NAME
, NULL
, window_style
,
925 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
926 hwndParent
, 0, explorerframe_hinstance
, This
);
930 ERR("Failed to create the window.\n");
931 return HRESULT_FROM_WIN32(GetLastError());
937 static HRESULT WINAPI
NSTC2_fnTreeAdvise(INameSpaceTreeControl2
* iface
, IUnknown
*handler
, DWORD
*cookie
)
939 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
941 TRACE("%p (%p, %p)\n", This
, handler
, cookie
);
945 /* Only one client supported */
946 if (This
->events
|| This
->customdraw
|| This
->dragdrop
)
949 /* FIXME: request INameSpaceTreeAccessible too */
950 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlEvents
, (void**)&This
->events
);
951 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlCustomDraw
, (void**)&This
->customdraw
);
952 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlDropHandler
, (void**)&This
->dragdrop
);
954 if (This
->events
|| This
->customdraw
|| This
->dragdrop
)
957 return *cookie
? S_OK
: E_FAIL
;
960 static HRESULT WINAPI
NSTC2_fnTreeUnadvise(INameSpaceTreeControl2
* iface
, DWORD cookie
)
962 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
964 TRACE("%p (%x)\n", This
, cookie
);
966 /* The cookie is ignored. */
970 INameSpaceTreeControlEvents_Release(This
->events
);
974 if (This
->customdraw
)
976 INameSpaceTreeControlCustomDraw_Release(This
->customdraw
);
977 This
->customdraw
= NULL
;
982 INameSpaceTreeControlDropHandler_Release(This
->dragdrop
);
983 This
->dragdrop
= NULL
;
989 static HRESULT WINAPI
NSTC2_fnInsertRoot(INameSpaceTreeControl2
* iface
,
992 SHCONTF grfEnumFlags
,
993 NSTCROOTSTYLE grfRootStyle
,
994 IShellItemFilter
*pif
)
996 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
998 struct list
*add_after_entry
;
999 HTREEITEM add_after_hitem
;
1002 TRACE("%p, %d, %p, %x, %x, %p\n", This
, iIndex
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1004 new_root
= HeapAlloc(GetProcessHeap(), 0, sizeof(nstc_root
));
1006 return E_OUTOFMEMORY
;
1008 new_root
->psi
= psiRoot
;
1009 new_root
->enum_flags
= grfEnumFlags
;
1010 new_root
->root_style
= grfRootStyle
;
1011 new_root
->pif
= pif
;
1013 /* We want to keep the roots in the internal list and in the
1014 * treeview in the same order. */
1015 add_after_entry
= &This
->roots
;
1016 for(i
= 0; i
< max(0, iIndex
) && list_next(&This
->roots
, add_after_entry
); i
++)
1017 add_after_entry
= list_next(&This
->roots
, add_after_entry
);
1019 if(add_after_entry
== &This
->roots
)
1020 add_after_hitem
= TVI_FIRST
;
1022 add_after_hitem
= LIST_ENTRY(add_after_entry
, nstc_root
, entry
)->htreeitem
;
1024 new_root
->htreeitem
= insert_shellitem(This
, psiRoot
, TVI_ROOT
, add_after_hitem
);
1025 if(!new_root
->htreeitem
)
1027 WARN("Failed to add the root.\n");
1028 HeapFree(GetProcessHeap(), 0, new_root
);
1032 list_add_after(add_after_entry
, &new_root
->entry
);
1033 events_OnItemAdded(This
, psiRoot
, TRUE
);
1035 if(grfRootStyle
& NSTCRS_HIDDEN
)
1038 tvi
.mask
= TVIF_STATEEX
;
1039 tvi
.uStateEx
= TVIS_EX_FLAT
;
1040 tvi
.hItem
= new_root
->htreeitem
;
1042 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1045 if(grfRootStyle
& NSTCRS_EXPANDED
)
1046 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_EXPAND
,
1047 (LPARAM
)new_root
->htreeitem
);
1052 static HRESULT WINAPI
NSTC2_fnAppendRoot(INameSpaceTreeControl2
* iface
,
1053 IShellItem
*psiRoot
,
1054 SHCONTF grfEnumFlags
,
1055 NSTCROOTSTYLE grfRootStyle
,
1056 IShellItemFilter
*pif
)
1058 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1060 TRACE("%p, %p, %x, %x, %p\n",
1061 This
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1063 root_count
= list_count(&This
->roots
);
1065 return INameSpaceTreeControl2_InsertRoot(iface
, root_count
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1068 static HRESULT WINAPI
NSTC2_fnRemoveRoot(INameSpaceTreeControl2
* iface
,
1069 IShellItem
*psiRoot
)
1071 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1072 nstc_root
*cursor
, *root
= NULL
;
1073 TRACE("%p (%p)\n", This
, psiRoot
);
1076 return E_NOINTERFACE
;
1078 LIST_FOR_EACH_ENTRY(cursor
, &This
->roots
, nstc_root
, entry
)
1082 hr
= IShellItem_Compare(psiRoot
, cursor
->psi
, SICHINT_DISPLAY
, &order
);
1090 TRACE("root %p\n", root
);
1093 events_OnItemDeleted(This
, root
->psi
, TRUE
);
1094 SendMessageW(This
->hwnd_tv
, TVM_DELETEITEM
, 0, (LPARAM
)root
->htreeitem
);
1095 list_remove(&root
->entry
);
1096 HeapFree(GetProcessHeap(), 0, root
);
1101 WARN("No matching root found.\n");
1106 static HRESULT WINAPI
NSTC2_fnRemoveAllRoots(INameSpaceTreeControl2
* iface
)
1108 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1109 nstc_root
*cur1
, *cur2
;
1111 TRACE("%p\n", This
);
1113 if (list_empty(&This
->roots
))
1114 return E_INVALIDARG
;
1116 LIST_FOR_EACH_ENTRY_SAFE(cur1
, cur2
, &This
->roots
, nstc_root
, entry
)
1117 INameSpaceTreeControl2_RemoveRoot(iface
, cur1
->psi
);
1122 static HRESULT WINAPI
NSTC2_fnGetRootItems(INameSpaceTreeControl2
* iface
,
1123 IShellItemArray
**ppsiaRootItems
)
1125 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1127 LPITEMIDLIST
*array
;
1131 TRACE("%p (%p)\n", This
, ppsiaRootItems
);
1133 count
= list_count(&This
->roots
);
1136 return E_INVALIDARG
;
1138 array
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPITEMIDLIST
)*count
);
1141 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1142 SHGetIDListFromObject((IUnknown
*)root
->psi
, &array
[i
++]);
1144 SHGetDesktopFolder(&psf
);
1145 hr
= SHCreateShellItemArray(NULL
, psf
, count
, (PCUITEMID_CHILD_ARRAY
)array
,
1147 IShellFolder_Release(psf
);
1149 for(i
= 0; i
< count
; i
++)
1152 HeapFree(GetProcessHeap(), 0, array
);
1157 static HRESULT WINAPI
NSTC2_fnSetItemState(INameSpaceTreeControl2
* iface
,
1159 NSTCITEMSTATE nstcisMask
,
1160 NSTCITEMSTATE nstcisFlags
)
1162 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1166 TRACE("%p (%p, %x, %x)\n", This
, psi
, nstcisMask
, nstcisFlags
);
1168 hitem
= treeitem_from_shellitem(This
, psi
);
1169 if(!hitem
) return E_INVALIDARG
;
1171 /* Passing both NSTCIS_SELECTED and NSTCIS_SELECTEDNOEXPAND results
1172 in two TVM_SETITEMW's */
1173 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTED
)
1175 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hitem
);
1176 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (LPARAM
)hitem
);
1178 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTEDNOEXPAND
)
1180 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
|TVSI_NOSINGLEEXPAND
, (LPARAM
)hitem
);
1183 /* If NSTCIS_EXPANDED is among the flags, the mask is ignored. */
1184 if((nstcisMask
|nstcisFlags
) & NSTCIS_EXPANDED
)
1186 WPARAM arg
= nstcisFlags
&NSTCIS_EXPANDED
? TVE_EXPAND
:TVE_COLLAPSE
;
1187 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, arg
, (LPARAM
)hitem
);
1190 if(nstcisMask
& NSTCIS_DISABLED
)
1191 tvi
.mask
= TVIF_STATE
| TVIF_STATEEX
;
1192 else if( ((nstcisMask
^nstcisFlags
) & (NSTCIS_SELECTED
|NSTCIS_EXPANDED
|NSTCIS_SELECTEDNOEXPAND
)) ||
1193 ((nstcisMask
|nstcisFlags
) & NSTCIS_BOLD
) ||
1194 (nstcisFlags
& NSTCIS_DISABLED
) )
1195 tvi
.mask
= TVIF_STATE
;
1201 tvi
.stateMask
= tvi
.state
= 0;
1202 tvi
.stateMask
|= ((nstcisFlags
^nstcisMask
)&NSTCIS_SELECTED
) ? TVIS_SELECTED
: 0;
1203 tvi
.stateMask
|= (nstcisMask
|nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1204 tvi
.state
|= (nstcisMask
&nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1206 if((nstcisMask
&NSTCIS_EXPANDED
)^(nstcisFlags
&NSTCIS_EXPANDED
))
1211 tvi
.uStateEx
= (nstcisFlags
&nstcisMask
)&NSTCIS_DISABLED
?TVIS_EX_DISABLED
:0;
1214 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1220 static HRESULT WINAPI
NSTC2_fnGetItemState(INameSpaceTreeControl2
* iface
,
1222 NSTCITEMSTATE nstcisMask
,
1223 NSTCITEMSTATE
*pnstcisFlags
)
1225 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1228 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcisMask
, pnstcisFlags
);
1230 hitem
= treeitem_from_shellitem(This
, psi
);
1232 return E_INVALIDARG
;
1237 tvi
.mask
= TVIF_STATE
;
1238 tvi
.stateMask
= TVIS_SELECTED
|TVIS_EXPANDED
|TVIS_BOLD
;
1240 if(nstcisMask
& NSTCIS_DISABLED
)
1241 tvi
.mask
|= TVIF_STATEEX
;
1243 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1244 *pnstcisFlags
|= (tvi
.state
& TVIS_SELECTED
)?NSTCIS_SELECTED
:0;
1245 *pnstcisFlags
|= (tvi
.state
& TVIS_EXPANDED
)?NSTCIS_EXPANDED
:0;
1246 *pnstcisFlags
|= (tvi
.state
& TVIS_BOLD
)?NSTCIS_BOLD
:0;
1247 *pnstcisFlags
|= (tvi
.uStateEx
& TVIS_EX_DISABLED
)?NSTCIS_DISABLED
:0;
1249 *pnstcisFlags
&= nstcisMask
;
1254 static HRESULT WINAPI
NSTC2_fnGetSelectedItems(INameSpaceTreeControl2
* iface
,
1255 IShellItemArray
**psiaItems
)
1257 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1258 IShellItem
*psiselected
;
1260 TRACE("%p (%p)\n", This
, psiaItems
);
1262 psiselected
= get_selected_shellitem(This
);
1269 return SHCreateShellItemArrayFromShellItem(psiselected
, &IID_IShellItemArray
,
1273 static HRESULT WINAPI
NSTC2_fnGetItemCustomState(INameSpaceTreeControl2
* iface
,
1277 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1278 FIXME("stub, %p (%p, %p)\n", This
, psi
, piStateNumber
);
1282 static HRESULT WINAPI
NSTC2_fnSetItemCustomState(INameSpaceTreeControl2
* iface
,
1286 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1287 FIXME("stub, %p (%p, %d)\n", This
, psi
, iStateNumber
);
1291 static HRESULT WINAPI
NSTC2_fnEnsureItemVisible(INameSpaceTreeControl2
* iface
,
1294 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1297 TRACE("%p (%p)\n", This
, psi
);
1299 hitem
= treeitem_from_shellitem(This
, psi
);
1302 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (WPARAM
)hitem
);
1306 return E_INVALIDARG
;
1309 static HRESULT WINAPI
NSTC2_fnSetTheme(INameSpaceTreeControl2
* iface
,
1312 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1313 FIXME("stub, %p (%p)\n", This
, pszTheme
);
1317 static HRESULT WINAPI
NSTC2_fnGetNextItem(INameSpaceTreeControl2
* iface
,
1320 IShellItem
**ppsiNext
)
1322 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1323 HTREEITEM hitem
, hnext
;
1325 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcgi
, ppsiNext
);
1327 if(!ppsiNext
) return E_POINTER
;
1328 if(!psi
) return E_FAIL
;
1332 hitem
= treeitem_from_shellitem(This
, psi
);
1334 return E_INVALIDARG
;
1338 case NSTCGNI_NEXT
: tvgn
= TVGN_NEXT
; break;
1339 case NSTCGNI_NEXTVISIBLE
: tvgn
= TVGN_NEXTVISIBLE
; break;
1340 case NSTCGNI_PREV
: tvgn
= TVGN_PREVIOUS
; break;
1341 case NSTCGNI_PREVVISIBLE
: tvgn
= TVGN_PREVIOUSVISIBLE
; break;
1342 case NSTCGNI_PARENT
: tvgn
= TVGN_PARENT
; break;
1343 case NSTCGNI_CHILD
: tvgn
= TVGN_CHILD
; break;
1344 case NSTCGNI_FIRSTVISIBLE
: tvgn
= TVGN_FIRSTVISIBLE
; break;
1345 case NSTCGNI_LASTVISIBLE
: tvgn
= TVGN_LASTVISIBLE
; break;
1347 FIXME("Unknown nstcgi value %d\n", nstcgi
);
1351 hnext
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, tvgn
, (WPARAM
)hitem
);
1354 *ppsiNext
= shellitem_from_treeitem(This
, hnext
);
1355 IShellItem_AddRef(*ppsiNext
);
1362 static HRESULT WINAPI
NSTC2_fnHitTest(INameSpaceTreeControl2
* iface
,
1364 IShellItem
**ppsiOut
)
1366 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1368 TRACE("%p (%p, %p)\n", This
, ppsiOut
, ppt
);
1370 if(!ppt
|| !ppsiOut
)
1375 hitem
= treeitem_from_point(This
, ppt
, NULL
);
1377 *ppsiOut
= shellitem_from_treeitem(This
, hitem
);
1381 IShellItem_AddRef(*ppsiOut
);
1388 static HRESULT WINAPI
NSTC2_fnGetItemRect(INameSpaceTreeControl2
* iface
,
1392 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1394 TRACE("%p (%p, %p)\n", This
, psi
, prect
);
1399 hitem
= treeitem_from_shellitem(This
, psi
);
1402 *(HTREEITEM
*)prect
= hitem
;
1403 if(SendMessageW(This
->hwnd_tv
, TVM_GETITEMRECT
, FALSE
, (LPARAM
)prect
))
1405 MapWindowPoints(This
->hwnd_tv
, HWND_DESKTOP
, (POINT
*)prect
, 2);
1410 return E_INVALIDARG
;
1413 static HRESULT WINAPI
NSTC2_fnCollapseAll(INameSpaceTreeControl2
* iface
)
1415 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1417 TRACE("%p\n", This
);
1419 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1420 collapse_all(This
, root
->htreeitem
);
1425 static HRESULT WINAPI
NSTC2_fnSetControlStyle(INameSpaceTreeControl2
* iface
,
1426 NSTCSTYLE nstcsMask
,
1427 NSTCSTYLE nstcsStyle
)
1429 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1430 static const DWORD tv_style_flags
=
1431 NSTCS_HASEXPANDOS
| NSTCS_HASLINES
| NSTCS_FULLROWSELECT
|
1432 NSTCS_HORIZONTALSCROLL
| NSTCS_ROOTHASEXPANDO
|
1433 NSTCS_SHOWSELECTIONALWAYS
| NSTCS_NOINFOTIP
| NSTCS_EVENHEIGHT
|
1434 NSTCS_DISABLEDRAGDROP
| NSTCS_NOEDITLABELS
| NSTCS_CHECKBOXES
;
1435 static const DWORD host_style_flags
= NSTCS_TABSTOP
| NSTCS_BORDER
;
1436 static const DWORD nstc_flags
=
1437 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
|
1438 NSTCS_FAVORITESMODE
| NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
|
1439 NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
| NSTCS_SHOWREFRESHBUTTON
;
1440 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1442 /* Fail if there is an attempt to set an unknown style. */
1443 if(nstcsMask
& ~(tv_style_flags
| host_style_flags
| nstc_flags
))
1446 if(nstcsMask
& tv_style_flags
)
1449 treeview_style_from_nstcs(This
, nstcsStyle
, nstcsMask
, &new_style
);
1450 SetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
, new_style
);
1453 /* Flags affecting the host window */
1454 if(nstcsMask
& NSTCS_BORDER
)
1456 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
);
1457 new_style
&= ~WS_BORDER
;
1458 new_style
|= nstcsStyle
& NSTCS_BORDER
? WS_BORDER
: 0;
1459 SetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
, new_style
);
1461 if(nstcsMask
& NSTCS_TABSTOP
)
1463 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
);
1464 new_style
&= ~WS_EX_CONTROLPARENT
;
1465 new_style
|= nstcsStyle
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
1466 SetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
, new_style
);
1469 if((nstcsStyle
& nstcsMask
) & unsupported_styles
)
1470 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1471 (nstcsStyle
& nstcsMask
),
1472 (nstcsStyle
& nstcsMask
) & unsupported_styles
);
1474 This
->style
&= ~nstcsMask
;
1475 This
->style
|= (nstcsStyle
& nstcsMask
);
1480 static HRESULT WINAPI
NSTC2_fnGetControlStyle(INameSpaceTreeControl2
* iface
,
1481 NSTCSTYLE nstcsMask
,
1482 NSTCSTYLE
*pnstcsStyle
)
1484 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1485 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1487 *pnstcsStyle
= (This
->style
& nstcsMask
);
1492 static HRESULT WINAPI
NSTC2_fnSetControlStyle2(INameSpaceTreeControl2
* iface
,
1493 NSTCSTYLE2 nstcsMask
,
1494 NSTCSTYLE2 nstcsStyle
)
1496 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1497 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1499 if((nstcsStyle
& nstcsMask
) & unsupported_styles2
)
1500 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1501 (nstcsStyle
& nstcsMask
),
1502 (nstcsStyle
& nstcsMask
) & unsupported_styles2
);
1504 This
->style2
&= ~nstcsMask
;
1505 This
->style2
|= (nstcsStyle
& nstcsMask
);
1510 static HRESULT WINAPI
NSTC2_fnGetControlStyle2(INameSpaceTreeControl2
* iface
,
1511 NSTCSTYLE2 nstcsMask
,
1512 NSTCSTYLE2
*pnstcsStyle
)
1514 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1515 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1517 *pnstcsStyle
= (This
->style2
& nstcsMask
);
1522 static const INameSpaceTreeControl2Vtbl vt_INameSpaceTreeControl2
= {
1523 NSTC2_fnQueryInterface
,
1528 NSTC2_fnTreeUnadvise
,
1532 NSTC2_fnRemoveAllRoots
,
1533 NSTC2_fnGetRootItems
,
1534 NSTC2_fnSetItemState
,
1535 NSTC2_fnGetItemState
,
1536 NSTC2_fnGetSelectedItems
,
1537 NSTC2_fnGetItemCustomState
,
1538 NSTC2_fnSetItemCustomState
,
1539 NSTC2_fnEnsureItemVisible
,
1541 NSTC2_fnGetNextItem
,
1543 NSTC2_fnGetItemRect
,
1544 NSTC2_fnCollapseAll
,
1545 NSTC2_fnSetControlStyle
,
1546 NSTC2_fnGetControlStyle
,
1547 NSTC2_fnSetControlStyle2
,
1548 NSTC2_fnGetControlStyle2
1551 /**************************************************************************
1552 * IOleWindow Implementation
1555 static HRESULT WINAPI
IOW_fnQueryInterface(IOleWindow
*iface
, REFIID riid
, void **ppvObject
)
1557 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1558 return INameSpaceTreeControl2_QueryInterface(&This
->INameSpaceTreeControl2_iface
, riid
, ppvObject
);
1561 static ULONG WINAPI
IOW_fnAddRef(IOleWindow
*iface
)
1563 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1564 return INameSpaceTreeControl2_AddRef(&This
->INameSpaceTreeControl2_iface
);
1567 static ULONG WINAPI
IOW_fnRelease(IOleWindow
*iface
)
1569 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1570 return INameSpaceTreeControl2_Release(&This
->INameSpaceTreeControl2_iface
);
1573 static HRESULT WINAPI
IOW_fnGetWindow(IOleWindow
*iface
, HWND
*phwnd
)
1575 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1576 TRACE("%p (%p)\n", This
, phwnd
);
1578 *phwnd
= This
->hwnd_main
;
1582 static HRESULT WINAPI
IOW_fnContextSensitiveHelp(IOleWindow
*iface
, BOOL fEnterMode
)
1584 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1585 TRACE("%p (%d)\n", This
, fEnterMode
);
1587 /* Not implemented */
1591 static const IOleWindowVtbl vt_IOleWindow
= {
1592 IOW_fnQueryInterface
,
1596 IOW_fnContextSensitiveHelp
1599 HRESULT
NamespaceTreeControl_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
1604 TRACE ("%p %s %p\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
1609 return CLASS_E_NOAGGREGATION
;
1611 EFRAME_LockModule();
1613 nstc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(NSTC2Impl
));
1615 return E_OUTOFMEMORY
;
1618 nstc
->INameSpaceTreeControl2_iface
.lpVtbl
= &vt_INameSpaceTreeControl2
;
1619 nstc
->IOleWindow_iface
.lpVtbl
= &vt_IOleWindow
;
1621 list_init(&nstc
->roots
);
1623 ret
= INameSpaceTreeControl2_QueryInterface(&nstc
->INameSpaceTreeControl2_iface
, riid
, ppv
);
1624 INameSpaceTreeControl2_Release(&nstc
->INameSpaceTreeControl2_iface
);
1626 TRACE("--(%p)\n", ppv
);