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"
36 #include "wine/heap.h"
38 #include "explorerframe_main.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(nstc
);
42 typedef struct nstc_root
{
46 NSTCROOTSTYLE root_style
;
47 IShellItemFilter
*pif
;
52 INameSpaceTreeControl2 INameSpaceTreeControl2_iface
;
53 IOleWindow IOleWindow_iface
;
59 WNDPROC tv_oldwndproc
;
65 INameSpaceTreeControlCustomDraw
*customdraw
;
66 INameSpaceTreeControlDropHandler
*dragdrop
;
67 INameSpaceTreeControlEvents
*events
;
70 static const DWORD unsupported_styles
=
71 NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
| NSTCS_FAVORITESMODE
|
72 NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
| NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
|
73 NSTCS_SHOWREFRESHBUTTON
| NSTCS_SPRINGEXPAND
| NSTCS_RICHTOOLTIP
| NSTCS_NOINDENTCHECKS
;
74 static const DWORD unsupported_styles2
=
75 NSTCS2_INTERRUPTNOTIFICATIONS
| NSTCS2_SHOWNULLSPACEMENU
| NSTCS2_DISPLAYPADDING
|
76 NSTCS2_DISPLAYPINNEDONLY
| NTSCS2_NOSINGLETONAUTOEXPAND
| NTSCS2_NEVERINSERTNONENUMERATED
;
78 static inline NSTC2Impl
*impl_from_INameSpaceTreeControl2(INameSpaceTreeControl2
*iface
)
80 return CONTAINING_RECORD(iface
, NSTC2Impl
, INameSpaceTreeControl2_iface
);
83 static inline NSTC2Impl
*impl_from_IOleWindow(IOleWindow
*iface
)
85 return CONTAINING_RECORD(iface
, NSTC2Impl
, IOleWindow_iface
);
88 /* Forward declarations */
89 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
);
91 /*************************************************************************
92 * NamespaceTree event wrappers
94 static HRESULT
events_OnGetDefaultIconIndex(NSTC2Impl
*This
, IShellItem
*psi
,
95 int *piDefaultIcon
, int *piOpenIcon
)
99 if(!This
->events
) return E_NOTIMPL
;
101 refcount
= IShellItem_AddRef(psi
);
102 ret
= INameSpaceTreeControlEvents_OnGetDefaultIconIndex(This
->events
, psi
, piDefaultIcon
, piOpenIcon
);
103 if(IShellItem_Release(psi
) < refcount
- 1)
104 ERR("ShellItem was released by client - please file a bug.\n");
108 static HRESULT
events_OnItemAdded(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
112 if(!This
->events
) return S_OK
;
114 refcount
= IShellItem_AddRef(psi
);
115 ret
= INameSpaceTreeControlEvents_OnItemAdded(This
->events
, psi
, fIsRoot
);
116 if(IShellItem_Release(psi
) < refcount
- 1)
117 ERR("ShellItem was released by client - please file a bug.\n");
121 static HRESULT
events_OnItemDeleted(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
125 if(!This
->events
) return S_OK
;
127 refcount
= IShellItem_AddRef(psi
);
128 ret
= INameSpaceTreeControlEvents_OnItemDeleted(This
->events
, psi
, fIsRoot
);
129 if(IShellItem_Release(psi
) < refcount
- 1)
130 ERR("ShellItem was released by client - please file a bug.\n");
134 static HRESULT
events_OnBeforeExpand(NSTC2Impl
*This
, IShellItem
*psi
)
138 if(!This
->events
) return S_OK
;
140 refcount
= IShellItem_AddRef(psi
);
141 ret
= INameSpaceTreeControlEvents_OnBeforeExpand(This
->events
, psi
);
142 if(IShellItem_Release(psi
) < refcount
- 1)
143 ERR("ShellItem was released by client - please file a bug.\n");
147 static HRESULT
events_OnAfterExpand(NSTC2Impl
*This
, IShellItem
*psi
)
151 if(!This
->events
) return S_OK
;
153 refcount
= IShellItem_AddRef(psi
);
154 ret
= INameSpaceTreeControlEvents_OnAfterExpand(This
->events
, psi
);
155 if(IShellItem_Release(psi
) < refcount
- 1)
156 ERR("ShellItem was released by client - please file a bug.\n");
160 static HRESULT
events_OnItemClick(NSTC2Impl
*This
, IShellItem
*psi
,
161 NSTCEHITTEST nstceHitTest
, NSTCECLICKTYPE nstceClickType
)
165 if(!This
->events
) return S_OK
;
167 refcount
= IShellItem_AddRef(psi
);
168 ret
= INameSpaceTreeControlEvents_OnItemClick(This
->events
, psi
, nstceHitTest
, nstceClickType
);
169 if(IShellItem_Release(psi
) < refcount
- 1)
170 ERR("ShellItem was released by client - please file a bug.\n");
174 static HRESULT
events_OnSelectionChanged(NSTC2Impl
*This
, IShellItemArray
*psia
)
176 if(!This
->events
) return S_OK
;
178 return INameSpaceTreeControlEvents_OnSelectionChanged(This
->events
, psia
);
181 static HRESULT
events_OnKeyboardInput(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
183 if(!This
->events
) return S_OK
;
185 return INameSpaceTreeControlEvents_OnKeyboardInput(This
->events
, uMsg
, wParam
, lParam
);
188 /*************************************************************************
189 * NamespaceTree helper functions
191 static DWORD
treeview_style_from_nstcs(NSTC2Impl
*This
, NSTCSTYLE nstcs
,
192 NSTCSTYLE nstcs_mask
, DWORD
*new_style
)
194 DWORD old_style
, tv_mask
= 0;
195 TRACE("%p, %x, %x, %p\n", This
, nstcs
, nstcs_mask
, new_style
);
198 old_style
= GetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
);
200 old_style
= /* The default */
201 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
|
202 WS_TABSTOP
| TVS_NOHSCROLL
| TVS_NONEVENHEIGHT
| TVS_INFOTIP
|
203 TVS_EDITLABELS
| TVS_TRACKSELECT
;
205 if(nstcs_mask
& NSTCS_HASEXPANDOS
) tv_mask
|= TVS_HASBUTTONS
;
206 if(nstcs_mask
& NSTCS_HASLINES
) tv_mask
|= TVS_HASLINES
;
207 if(nstcs_mask
& NSTCS_FULLROWSELECT
) tv_mask
|= TVS_FULLROWSELECT
;
208 if(nstcs_mask
& NSTCS_HORIZONTALSCROLL
) tv_mask
|= TVS_NOHSCROLL
;
209 if(nstcs_mask
& NSTCS_ROOTHASEXPANDO
) tv_mask
|= TVS_LINESATROOT
;
210 if(nstcs_mask
& NSTCS_SHOWSELECTIONALWAYS
) tv_mask
|= TVS_SHOWSELALWAYS
;
211 if(nstcs_mask
& NSTCS_NOINFOTIP
) tv_mask
|= TVS_INFOTIP
;
212 if(nstcs_mask
& NSTCS_EVENHEIGHT
) tv_mask
|= TVS_NONEVENHEIGHT
;
213 if(nstcs_mask
& NSTCS_DISABLEDRAGDROP
) tv_mask
|= TVS_DISABLEDRAGDROP
;
214 if(nstcs_mask
& NSTCS_NOEDITLABELS
) tv_mask
|= TVS_EDITLABELS
;
215 if(nstcs_mask
& NSTCS_CHECKBOXES
) tv_mask
|= TVS_CHECKBOXES
;
216 if(nstcs_mask
& NSTCS_SINGLECLICKEXPAND
) tv_mask
|= TVS_SINGLEEXPAND
;
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
;
231 if(nstcs
& NSTCS_SINGLECLICKEXPAND
) *new_style
|= TVS_SINGLEEXPAND
;
233 *new_style
= (old_style
& ~tv_mask
) | (*new_style
& tv_mask
);
235 TRACE("old: %08x, new: %08x\n", old_style
, *new_style
);
237 return old_style
^*new_style
;
240 static IShellItem
*shellitem_from_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
244 tvi
.mask
= TVIF_PARAM
;
248 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
250 TRACE("ShellItem: %p\n", (void*)tvi
.lParam
);
251 return (IShellItem
*)tvi
.lParam
;
254 /* Returns the root that the given treeitem belongs to. */
255 static nstc_root
*root_for_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
257 HTREEITEM tmp
, hroot
= hitem
;
260 /* Work our way up the hierarchy */
261 for(tmp
= hitem
; tmp
!= NULL
; hroot
= tmp
?tmp
:hroot
)
262 tmp
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)hroot
);
264 /* Search through the list of roots for a match */
265 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
266 if(root
->htreeitem
== hroot
)
269 TRACE("root is %p\n", root
);
273 /* Find a shellitem in the tree, starting from the given node. */
274 static HTREEITEM
search_for_shellitem(NSTC2Impl
*This
, HTREEITEM node
,
277 IShellItem
*psi_node
;
278 HTREEITEM next
, result
= NULL
;
281 TRACE("%p, %p, %p\n", This
, node
, psi
);
283 /* Check this node */
284 psi_node
= shellitem_from_treeitem(This
, node
);
285 hr
= IShellItem_Compare(psi
, psi_node
, SICHINT_DISPLAY
, &cmpo
);
290 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
291 TVGN_CHILD
, (LPARAM
)node
);
294 result
= search_for_shellitem(This
, next
, psi
);
295 if(result
) return result
;
298 /* Try our next sibling. */
299 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
300 TVGN_NEXT
, (LPARAM
)node
);
302 result
= search_for_shellitem(This
, next
, psi
);
307 static HTREEITEM
treeitem_from_shellitem(NSTC2Impl
*This
, IShellItem
*psi
)
310 TRACE("%p, %p\n", This
, psi
);
312 root
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
317 return search_for_shellitem(This
, root
, psi
);
320 static int get_icon(LPCITEMIDLIST lpi
, UINT extra_flags
)
323 UINT flags
= SHGFI_PIDL
| SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
;
326 list
= (IImageList
*)SHGetFileInfoW((LPCWSTR
)lpi
, 0 ,&sfi
, sizeof(SHFILEINFOW
), flags
| extra_flags
);
327 if (list
) IImageList_Release(list
);
331 /* Insert a shellitem into the given place in the tree and return the
332 resulting treeitem. */
333 static HTREEITEM
insert_shellitem(NSTC2Impl
*This
, IShellItem
*psi
,
334 HTREEITEM hParent
, HTREEITEM hInsertAfter
)
336 TVINSERTSTRUCTW tvins
;
337 TVITEMEXW
*tvi
= &tvins
.u
.itemex
;
339 TRACE("%p (%p, %p)\n", psi
, hParent
, hInsertAfter
);
341 tvi
->mask
= TVIF_PARAM
| TVIF_CHILDREN
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_TEXT
;
342 tvi
->cChildren
= I_CHILDRENCALLBACK
;
343 tvi
->iImage
= tvi
->iSelectedImage
= I_IMAGECALLBACK
;
344 tvi
->pszText
= LPSTR_TEXTCALLBACKW
;
346 /* Every treeitem contains a pointer to the corresponding ShellItem. */
347 tvi
->lParam
= (LPARAM
)psi
;
348 tvins
.hParent
= hParent
;
349 tvins
.hInsertAfter
= hInsertAfter
;
351 hinserted
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_INSERTITEMW
, 0,
352 (LPARAM
)(LPTVINSERTSTRUCTW
)&tvins
);
354 IShellItem_AddRef(psi
);
359 /* Enumerates the children of the folder represented by hitem
360 * according to the settings for the root, and adds them to the
361 * treeview. Returns the number of children added. */
362 static UINT
fill_sublevel(NSTC2Impl
*This
, HTREEITEM hitem
)
364 IShellItem
*psiParent
= shellitem_from_treeitem(This
, hitem
);
365 nstc_root
*root
= root_for_treeitem(This
, hitem
);
366 LPITEMIDLIST pidl_parent
;
372 hr
= SHGetIDListFromObject((IUnknown
*)psiParent
, &pidl_parent
);
375 hr
= IShellItem_BindToHandler(psiParent
, NULL
, &BHID_SFObject
, &IID_IShellFolder
, (void**)&psf
);
378 hr
= IShellFolder_EnumObjects(psf
, NULL
, root
->enum_flags
, &peidl
);
385 while( S_OK
== IEnumIDList_Next(peidl
, 1, &pidl
, &fetched
) )
387 hr
= SHCreateShellItem(NULL
, psf
, pidl
, &psi
);
391 if(insert_shellitem(This
, psi
, hitem
, NULL
))
393 events_OnItemAdded(This
, psi
, FALSE
);
397 IShellItem_Release(psi
);
400 ERR("SHCreateShellItem failed with 0x%08x\n", hr
);
402 IEnumIDList_Release(peidl
);
405 ERR("EnumObjects failed with 0x%08x\n", hr
);
407 IShellFolder_Release(psf
);
410 ERR("BindToHandler failed with 0x%08x\n", hr
);
415 ERR("SHGetIDListFromObject failed with 0x%08x\n", hr
);
420 static HTREEITEM
get_selected_treeitem(NSTC2Impl
*This
)
422 return (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
425 static IShellItem
*get_selected_shellitem(NSTC2Impl
*This
)
427 return shellitem_from_treeitem(This
, get_selected_treeitem(This
));
430 static void collapse_all(NSTC2Impl
*This
, HTREEITEM node
)
434 /* Collapse this node first, and then first child/next sibling. */
435 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_COLLAPSE
, (LPARAM
)node
);
437 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
438 if(next
) collapse_all(This
, next
);
440 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_NEXT
, (LPARAM
)node
);
441 if(next
) collapse_all(This
, next
);
444 static HTREEITEM
treeitem_from_point(NSTC2Impl
*This
, const POINT
*pt
, UINT
*hitflag
)
451 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tviht
);
452 if(hitflag
) *hitflag
= tviht
.flags
;
456 /*************************************************************************
457 * NamespaceTree window functions
459 static LRESULT
create_namespacetree(HWND hWnd
, CREATESTRUCTW
*crs
)
461 NSTC2Impl
*This
= crs
->lpCreateParams
;
462 HIMAGELIST ShellSmallIconList
;
463 DWORD treeview_style
, treeview_ex_style
;
465 TRACE("%p (%p)\n", This
, crs
);
466 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (LPARAM
)This
);
467 This
->hwnd_main
= hWnd
;
469 treeview_style_from_nstcs(This
, This
->style
, 0xFFFFFFFF, &treeview_style
);
471 This
->hwnd_tv
= CreateWindowExW(0, WC_TREEVIEWW
, NULL
, treeview_style
,
472 0, 0, crs
->cx
, crs
->cy
,
473 hWnd
, NULL
, explorerframe_hinstance
, NULL
);
477 ERR("Failed to create treeview!\n");
478 return HRESULT_FROM_WIN32(GetLastError());
481 treeview_ex_style
= TVS_EX_DRAWIMAGEASYNC
| TVS_EX_RICHTOOLTIP
|
482 TVS_EX_DOUBLEBUFFER
| TVS_EX_NOSINGLECOLLAPSE
;
484 if(This
->style
& NSTCS_AUTOHSCROLL
)
485 treeview_ex_style
|= TVS_EX_AUTOHSCROLL
;
486 if(This
->style
& NSTCS_FADEINOUTEXPANDOS
)
487 treeview_ex_style
|= TVS_EX_FADEINOUTEXPANDOS
;
488 if(This
->style
& NSTCS_PARTIALCHECKBOXES
)
489 treeview_ex_style
|= TVS_EX_PARTIALCHECKBOXES
;
490 if(This
->style
& NSTCS_EXCLUSIONCHECKBOXES
)
491 treeview_ex_style
|= TVS_EX_EXCLUSIONCHECKBOXES
;
492 if(This
->style
& NSTCS_DIMMEDCHECKBOXES
)
493 treeview_ex_style
|= TVS_EX_DIMMEDCHECKBOXES
;
495 SendMessageW(This
->hwnd_tv
, TVM_SETEXTENDEDSTYLE
, treeview_ex_style
, 0xffff);
497 if(Shell_GetImageLists(NULL
, &ShellSmallIconList
))
499 SendMessageW(This
->hwnd_tv
, TVM_SETIMAGELIST
,
500 (WPARAM
)TVSIL_NORMAL
, (LPARAM
)ShellSmallIconList
);
504 ERR("Failed to get the System Image List.\n");
507 INameSpaceTreeControl2_AddRef(&This
->INameSpaceTreeControl2_iface
);
509 /* Subclass the treeview to get the keyboard events. */
510 This
->tv_oldwndproc
= (WNDPROC
)SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
,
511 (ULONG_PTR
)tv_wndproc
);
512 if(This
->tv_oldwndproc
)
513 SetPropW(This
->hwnd_tv
, L
"PROP_THIS", This
);
518 static LRESULT
resize_namespacetree(NSTC2Impl
*This
)
523 GetClientRect(This
->hwnd_main
, &rc
);
524 MoveWindow(This
->hwnd_tv
, 0, 0, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, TRUE
);
529 static LRESULT
destroy_namespacetree(NSTC2Impl
*This
)
533 /* Undo the subclassing */
534 if(This
->tv_oldwndproc
)
536 SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
, (ULONG_PTR
)This
->tv_oldwndproc
);
537 RemovePropW(This
->hwnd_tv
, L
"PROP_THIS");
540 INameSpaceTreeControl2_RemoveAllRoots(&This
->INameSpaceTreeControl2_iface
);
542 /* This reference was added in create_namespacetree */
543 INameSpaceTreeControl2_Release(&This
->INameSpaceTreeControl2_iface
);
547 static LRESULT
on_tvn_deleteitemw(NSTC2Impl
*This
, LPARAM lParam
)
549 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
552 IShellItem_Release((IShellItem
*)nmtv
->itemOld
.lParam
);
556 static LRESULT
on_tvn_getdispinfow(NSTC2Impl
*This
, LPARAM lParam
)
558 NMTVDISPINFOW
*dispinfo
= (NMTVDISPINFOW
*)lParam
;
559 TVITEMEXW
*item
= (TVITEMEXW
*)&dispinfo
->item
;
560 IShellItem
*psi
= shellitem_from_treeitem(This
, item
->hItem
);
563 TRACE("%p, %p (mask: %x)\n", This
, dispinfo
, item
->mask
);
565 if(item
->mask
& TVIF_CHILDREN
)
569 hr
= IShellItem_GetAttributes(psi
, SFGAO_HASSUBFOLDER
, &sfgao
);
571 item
->cChildren
= (sfgao
& SFGAO_HASSUBFOLDER
)?1:0;
575 item
->mask
|= TVIF_DI_SETITEM
;
578 if(item
->mask
& (TVIF_IMAGE
|TVIF_SELECTEDIMAGE
))
582 hr
= events_OnGetDefaultIconIndex(This
, psi
, &item
->iImage
, &item
->iSelectedImage
);
585 hr
= SHGetIDListFromObject((IUnknown
*)psi
, &pidl
);
588 item
->iImage
= item
->iSelectedImage
= get_icon(pidl
, 0);
589 item
->mask
|= TVIF_DI_SETITEM
;
593 ERR("Failed to get IDList (%08x).\n", hr
);
597 if(item
->mask
& TVIF_TEXT
)
601 hr
= IShellItem_GetDisplayName(psi
, SIGDN_NORMALDISPLAY
, &display_name
);
604 lstrcpynW(item
->pszText
, display_name
, MAX_PATH
);
605 item
->mask
|= TVIF_DI_SETITEM
;
606 CoTaskMemFree(display_name
);
609 ERR("Failed to get display name (%08x).\n", hr
);
615 static BOOL
treenode_has_subfolders(NSTC2Impl
*This
, HTREEITEM node
)
617 return SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
620 static LRESULT
on_tvn_itemexpandingw(NSTC2Impl
*This
, LPARAM lParam
)
622 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
626 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
627 events_OnBeforeExpand(This
, psi
);
629 if(!treenode_has_subfolders(This
, nmtv
->itemNew
.hItem
))
631 /* The node has no children, try to find some */
632 if(!fill_sublevel(This
, nmtv
->itemNew
.hItem
))
635 /* Failed to enumerate any children, remove the expando
637 tvi
.hItem
= nmtv
->itemNew
.hItem
;
638 tvi
.mask
= TVIF_CHILDREN
;
640 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
648 static LRESULT
on_tvn_itemexpandedw(NSTC2Impl
*This
, LPARAM lParam
)
650 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
654 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
655 events_OnAfterExpand(This
, psi
);
659 static LRESULT
on_tvn_selchangedw(NSTC2Impl
*This
, LPARAM lParam
)
661 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
662 IShellItemArray
*psia
;
667 /* Note: Only supports one selected item. */
668 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
669 hr
= SHCreateShellItemArrayFromShellItem(psi
, &IID_IShellItemArray
, (void**)&psia
);
672 events_OnSelectionChanged(This
, psia
);
673 IShellItemArray_Release(psia
);
679 static LRESULT
on_nm_click(NSTC2Impl
*This
, NMHDR
*nmhdr
)
684 TRACE("%p (%p)\n", This
, nmhdr
);
686 GetCursorPos(&tvhit
.pt
);
687 ScreenToClient(This
->hwnd_tv
, &tvhit
.pt
);
688 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
690 if(tvhit
.flags
& (TVHT_NOWHERE
|TVHT_ABOVE
|TVHT_BELOW
))
693 /* TVHT_ maps onto the corresponding NSTCEHT_ */
694 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
695 return FAILED(events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_LBUTTON
));
698 static LRESULT
on_wm_mbuttonup(NSTC2Impl
*This
, WPARAM wParam
, LPARAM lParam
)
703 TRACE("%p (%lx, %lx)\n", This
, wParam
, lParam
);
705 tvhit
.pt
.x
= (int)(short)LOWORD(lParam
);
706 tvhit
.pt
.y
= (int)(short)HIWORD(lParam
);
708 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
710 /* Seems to generate only ONITEM and ONITEMICON */
711 if( !(tvhit
.flags
& (TVHT_ONITEM
|TVHT_ONITEMICON
)) )
714 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
715 hr
= events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_MBUTTON
);
723 static LRESULT
on_kbd_event(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
727 TRACE("%p : %d, %lx, %lx\n", This
, uMsg
, wParam
, lParam
);
729 /* Handled by the client? */
730 if(FAILED(events_OnKeyboardInput(This
, uMsg
, wParam
, lParam
)))
733 if(uMsg
== WM_KEYDOWN
)
738 psi
= get_selected_shellitem(This
);
739 FIXME("Deletion of file requested (shellitem: %p).\n", psi
);
743 hitem
= get_selected_treeitem(This
);
744 SendMessageW(This
->hwnd_tv
, TVM_EDITLABELW
, 0, (LPARAM
)hitem
);
749 /* Let the TreeView handle the key */
753 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
)
755 NSTC2Impl
*This
= (NSTC2Impl
*)GetPropW(hWnd
, L
"PROP_THIS");
764 if(on_kbd_event(This
, uMessage
, wParam
, lParam
))
768 case WM_MBUTTONUP
: return on_wm_mbuttonup(This
, wParam
, lParam
);
771 /* Pass the message on to the treeview */
772 return CallWindowProcW(This
->tv_oldwndproc
, hWnd
, uMessage
, wParam
, lParam
);
775 static LRESULT CALLBACK
NSTC2_WndProc(HWND hWnd
, UINT uMessage
,
776 WPARAM wParam
, LPARAM lParam
)
778 NSTC2Impl
*This
= (NSTC2Impl
*)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
783 case WM_NCCREATE
: return create_namespacetree(hWnd
, (CREATESTRUCTW
*)lParam
);
784 case WM_SIZE
: return resize_namespacetree(This
);
785 case WM_DESTROY
: return destroy_namespacetree(This
);
787 nmhdr
= (NMHDR
*)lParam
;
790 case NM_CLICK
: return on_nm_click(This
, nmhdr
);
791 case TVN_DELETEITEMW
: return on_tvn_deleteitemw(This
, lParam
);
792 case TVN_GETDISPINFOW
: return on_tvn_getdispinfow(This
, lParam
);
793 case TVN_ITEMEXPANDINGW
: return on_tvn_itemexpandingw(This
, lParam
);
794 case TVN_ITEMEXPANDEDW
: return on_tvn_itemexpandedw(This
, lParam
);
795 case TVN_SELCHANGEDW
: return on_tvn_selchangedw(This
, lParam
);
799 default: return DefWindowProcW(hWnd
, uMessage
, wParam
, lParam
);
804 /**************************************************************************
805 * INameSpaceTreeControl2 Implementation
807 static HRESULT WINAPI
NSTC2_fnQueryInterface(INameSpaceTreeControl2
* iface
,
811 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
812 TRACE("%p (%s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
815 if(IsEqualIID(riid
, &IID_INameSpaceTreeControl2
) ||
816 IsEqualIID(riid
, &IID_INameSpaceTreeControl
) ||
817 IsEqualIID(riid
, &IID_IUnknown
))
819 *ppvObject
= &This
->INameSpaceTreeControl2_iface
;
821 else if(IsEqualIID(riid
, &IID_IOleWindow
))
823 *ppvObject
= &This
->IOleWindow_iface
;
828 IUnknown_AddRef((IUnknown
*)*ppvObject
);
832 return E_NOINTERFACE
;
835 static ULONG WINAPI
NSTC2_fnAddRef(INameSpaceTreeControl2
* iface
)
837 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
838 LONG ref
= InterlockedIncrement(&This
->ref
);
840 TRACE("%p - ref %d\n", This
, ref
);
845 static ULONG WINAPI
NSTC2_fnRelease(INameSpaceTreeControl2
* iface
)
847 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
848 LONG ref
= InterlockedDecrement(&This
->ref
);
850 TRACE("%p - ref: %d\n", This
, ref
);
856 EFRAME_UnlockModule();
862 static HRESULT WINAPI
NSTC2_fnInitialize(INameSpaceTreeControl2
* iface
,
865 NSTCSTYLE nstcsFlags
)
867 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
869 DWORD window_style
, window_ex_style
;
870 INITCOMMONCONTROLSEX icex
;
872 static const WCHAR NSTC2_CLASS_NAME
[] = L
"NamespaceTreeControl";
874 TRACE("%p (%p, %p, %x)\n", This
, hwndParent
, prc
, nstcsFlags
);
876 if(nstcsFlags
& unsupported_styles
)
877 FIXME("0x%08x contains the unsupported style(s) 0x%08x\n",
878 nstcsFlags
, nstcsFlags
& unsupported_styles
);
880 This
->style
= nstcsFlags
;
882 icex
.dwSize
= sizeof( icex
);
883 icex
.dwICC
= ICC_TREEVIEW_CLASSES
;
884 InitCommonControlsEx( &icex
);
886 if(!GetClassInfoW(explorerframe_hinstance
, NSTC2_CLASS_NAME
, &wc
))
888 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
889 wc
.lpfnWndProc
= NSTC2_WndProc
;
892 wc
.hInstance
= explorerframe_hinstance
;
894 wc
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
895 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
896 wc
.lpszMenuName
= NULL
;
897 wc
.lpszClassName
= NSTC2_CLASS_NAME
;
899 if (!RegisterClassW(&wc
)) return E_FAIL
;
902 /* NSTCS_TABSTOP and NSTCS_BORDER affects the host window */
903 window_style
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
|
904 (nstcsFlags
& NSTCS_BORDER
? WS_BORDER
: 0);
905 window_ex_style
= nstcsFlags
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
912 This
->hwnd_main
= CreateWindowExW(window_ex_style
, NSTC2_CLASS_NAME
, NULL
, window_style
,
913 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
914 hwndParent
, 0, explorerframe_hinstance
, This
);
918 ERR("Failed to create the window.\n");
919 return HRESULT_FROM_WIN32(GetLastError());
925 static HRESULT WINAPI
NSTC2_fnTreeAdvise(INameSpaceTreeControl2
* iface
, IUnknown
*handler
, DWORD
*cookie
)
927 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
929 TRACE("%p (%p, %p)\n", This
, handler
, cookie
);
933 /* Only one client supported */
934 if (This
->events
|| This
->customdraw
|| This
->dragdrop
)
937 /* FIXME: request INameSpaceTreeAccessible too */
938 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlEvents
, (void**)&This
->events
);
939 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlCustomDraw
, (void**)&This
->customdraw
);
940 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlDropHandler
, (void**)&This
->dragdrop
);
942 if (This
->events
|| This
->customdraw
|| This
->dragdrop
)
945 return *cookie
? S_OK
: E_FAIL
;
948 static HRESULT WINAPI
NSTC2_fnTreeUnadvise(INameSpaceTreeControl2
* iface
, DWORD cookie
)
950 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
952 TRACE("%p (%x)\n", This
, cookie
);
954 /* The cookie is ignored. */
958 INameSpaceTreeControlEvents_Release(This
->events
);
962 if (This
->customdraw
)
964 INameSpaceTreeControlCustomDraw_Release(This
->customdraw
);
965 This
->customdraw
= NULL
;
970 INameSpaceTreeControlDropHandler_Release(This
->dragdrop
);
971 This
->dragdrop
= NULL
;
977 static HRESULT WINAPI
NSTC2_fnInsertRoot(INameSpaceTreeControl2
* iface
,
980 SHCONTF grfEnumFlags
,
981 NSTCROOTSTYLE grfRootStyle
,
982 IShellItemFilter
*pif
)
984 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
986 struct list
*add_after_entry
;
987 HTREEITEM add_after_hitem
;
990 TRACE("%p, %d, %p, %x, %x, %p\n", This
, iIndex
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
992 new_root
= heap_alloc(sizeof(*new_root
));
994 return E_OUTOFMEMORY
;
996 new_root
->psi
= psiRoot
;
997 new_root
->enum_flags
= grfEnumFlags
;
998 new_root
->root_style
= grfRootStyle
;
1001 /* We want to keep the roots in the internal list and in the
1002 * treeview in the same order. */
1003 add_after_entry
= &This
->roots
;
1004 for(i
= 0; i
< max(0, iIndex
) && list_next(&This
->roots
, add_after_entry
); i
++)
1005 add_after_entry
= list_next(&This
->roots
, add_after_entry
);
1007 if(add_after_entry
== &This
->roots
)
1008 add_after_hitem
= TVI_FIRST
;
1010 add_after_hitem
= LIST_ENTRY(add_after_entry
, nstc_root
, entry
)->htreeitem
;
1012 new_root
->htreeitem
= insert_shellitem(This
, psiRoot
, TVI_ROOT
, add_after_hitem
);
1013 if(!new_root
->htreeitem
)
1015 WARN("Failed to add the root.\n");
1016 heap_free(new_root
);
1020 list_add_after(add_after_entry
, &new_root
->entry
);
1021 events_OnItemAdded(This
, psiRoot
, TRUE
);
1023 if(grfRootStyle
& NSTCRS_HIDDEN
)
1026 tvi
.mask
= TVIF_STATEEX
;
1027 tvi
.uStateEx
= TVIS_EX_FLAT
;
1028 tvi
.hItem
= new_root
->htreeitem
;
1030 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1033 if(grfRootStyle
& NSTCRS_EXPANDED
)
1034 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_EXPAND
,
1035 (LPARAM
)new_root
->htreeitem
);
1040 static HRESULT WINAPI
NSTC2_fnAppendRoot(INameSpaceTreeControl2
* iface
,
1041 IShellItem
*psiRoot
,
1042 SHCONTF grfEnumFlags
,
1043 NSTCROOTSTYLE grfRootStyle
,
1044 IShellItemFilter
*pif
)
1046 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1048 TRACE("%p, %p, %x, %x, %p\n",
1049 This
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1051 root_count
= list_count(&This
->roots
);
1053 return INameSpaceTreeControl2_InsertRoot(iface
, root_count
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1056 static HRESULT WINAPI
NSTC2_fnRemoveRoot(INameSpaceTreeControl2
* iface
,
1057 IShellItem
*psiRoot
)
1059 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1060 nstc_root
*cursor
, *root
= NULL
;
1061 TRACE("%p (%p)\n", This
, psiRoot
);
1064 return E_NOINTERFACE
;
1066 LIST_FOR_EACH_ENTRY(cursor
, &This
->roots
, nstc_root
, entry
)
1070 hr
= IShellItem_Compare(psiRoot
, cursor
->psi
, SICHINT_DISPLAY
, &order
);
1078 TRACE("root %p\n", root
);
1081 events_OnItemDeleted(This
, root
->psi
, TRUE
);
1082 SendMessageW(This
->hwnd_tv
, TVM_DELETEITEM
, 0, (LPARAM
)root
->htreeitem
);
1083 list_remove(&root
->entry
);
1089 WARN("No matching root found.\n");
1094 static HRESULT WINAPI
NSTC2_fnRemoveAllRoots(INameSpaceTreeControl2
* iface
)
1096 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1097 nstc_root
*cur1
, *cur2
;
1099 TRACE("%p\n", This
);
1101 if (list_empty(&This
->roots
))
1102 return E_INVALIDARG
;
1104 LIST_FOR_EACH_ENTRY_SAFE(cur1
, cur2
, &This
->roots
, nstc_root
, entry
)
1105 INameSpaceTreeControl2_RemoveRoot(iface
, cur1
->psi
);
1110 static HRESULT WINAPI
NSTC2_fnGetRootItems(INameSpaceTreeControl2
* iface
,
1111 IShellItemArray
**ppsiaRootItems
)
1113 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1115 LPITEMIDLIST
*array
;
1119 TRACE("%p (%p)\n", This
, ppsiaRootItems
);
1121 count
= list_count(&This
->roots
);
1124 return E_INVALIDARG
;
1126 array
= heap_alloc(sizeof(LPITEMIDLIST
)*count
);
1129 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1130 SHGetIDListFromObject((IUnknown
*)root
->psi
, &array
[i
++]);
1132 SHGetDesktopFolder(&psf
);
1133 hr
= SHCreateShellItemArray(NULL
, psf
, count
, (PCUITEMID_CHILD_ARRAY
)array
,
1135 IShellFolder_Release(psf
);
1137 for(i
= 0; i
< count
; i
++)
1145 static HRESULT WINAPI
NSTC2_fnSetItemState(INameSpaceTreeControl2
* iface
,
1147 NSTCITEMSTATE nstcisMask
,
1148 NSTCITEMSTATE nstcisFlags
)
1150 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1154 TRACE("%p (%p, %x, %x)\n", This
, psi
, nstcisMask
, nstcisFlags
);
1156 hitem
= treeitem_from_shellitem(This
, psi
);
1157 if(!hitem
) return E_INVALIDARG
;
1159 /* Passing both NSTCIS_SELECTED and NSTCIS_SELECTEDNOEXPAND results
1160 in two TVM_SETITEMW's */
1161 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTED
)
1163 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hitem
);
1164 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (LPARAM
)hitem
);
1166 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTEDNOEXPAND
)
1168 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
|TVSI_NOSINGLEEXPAND
, (LPARAM
)hitem
);
1171 /* If NSTCIS_EXPANDED is among the flags, the mask is ignored. */
1172 if((nstcisMask
|nstcisFlags
) & NSTCIS_EXPANDED
)
1174 WPARAM arg
= nstcisFlags
&NSTCIS_EXPANDED
? TVE_EXPAND
:TVE_COLLAPSE
;
1175 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, arg
, (LPARAM
)hitem
);
1178 if(nstcisMask
& NSTCIS_DISABLED
)
1179 tvi
.mask
= TVIF_STATE
| TVIF_STATEEX
;
1180 else if( ((nstcisMask
^nstcisFlags
) & (NSTCIS_SELECTED
|NSTCIS_EXPANDED
|NSTCIS_SELECTEDNOEXPAND
)) ||
1181 ((nstcisMask
|nstcisFlags
) & NSTCIS_BOLD
) ||
1182 (nstcisFlags
& NSTCIS_DISABLED
) )
1183 tvi
.mask
= TVIF_STATE
;
1189 tvi
.stateMask
= tvi
.state
= 0;
1190 tvi
.stateMask
|= ((nstcisFlags
^nstcisMask
)&NSTCIS_SELECTED
) ? TVIS_SELECTED
: 0;
1191 tvi
.stateMask
|= (nstcisMask
|nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1192 tvi
.state
|= (nstcisMask
&nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1194 if((nstcisMask
&NSTCIS_EXPANDED
)^(nstcisFlags
&NSTCIS_EXPANDED
))
1199 tvi
.uStateEx
= (nstcisFlags
&nstcisMask
)&NSTCIS_DISABLED
?TVIS_EX_DISABLED
:0;
1202 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1208 static HRESULT WINAPI
NSTC2_fnGetItemState(INameSpaceTreeControl2
* iface
,
1210 NSTCITEMSTATE nstcisMask
,
1211 NSTCITEMSTATE
*pnstcisFlags
)
1213 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1216 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcisMask
, pnstcisFlags
);
1218 hitem
= treeitem_from_shellitem(This
, psi
);
1220 return E_INVALIDARG
;
1225 tvi
.mask
= TVIF_STATE
;
1226 tvi
.stateMask
= TVIS_SELECTED
|TVIS_EXPANDED
|TVIS_BOLD
;
1228 if(nstcisMask
& NSTCIS_DISABLED
)
1229 tvi
.mask
|= TVIF_STATEEX
;
1231 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1232 *pnstcisFlags
|= (tvi
.state
& TVIS_SELECTED
)?NSTCIS_SELECTED
:0;
1233 *pnstcisFlags
|= (tvi
.state
& TVIS_EXPANDED
)?NSTCIS_EXPANDED
:0;
1234 *pnstcisFlags
|= (tvi
.state
& TVIS_BOLD
)?NSTCIS_BOLD
:0;
1235 *pnstcisFlags
|= (tvi
.uStateEx
& TVIS_EX_DISABLED
)?NSTCIS_DISABLED
:0;
1237 *pnstcisFlags
&= nstcisMask
;
1242 static HRESULT WINAPI
NSTC2_fnGetSelectedItems(INameSpaceTreeControl2
* iface
,
1243 IShellItemArray
**psiaItems
)
1245 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1246 IShellItem
*psiselected
;
1248 TRACE("%p (%p)\n", This
, psiaItems
);
1250 psiselected
= get_selected_shellitem(This
);
1257 return SHCreateShellItemArrayFromShellItem(psiselected
, &IID_IShellItemArray
,
1261 static HRESULT WINAPI
NSTC2_fnGetItemCustomState(INameSpaceTreeControl2
* iface
,
1265 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1266 FIXME("stub, %p (%p, %p)\n", This
, psi
, piStateNumber
);
1270 static HRESULT WINAPI
NSTC2_fnSetItemCustomState(INameSpaceTreeControl2
* iface
,
1274 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1275 FIXME("stub, %p (%p, %d)\n", This
, psi
, iStateNumber
);
1279 static HRESULT WINAPI
NSTC2_fnEnsureItemVisible(INameSpaceTreeControl2
* iface
,
1282 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1285 TRACE("%p (%p)\n", This
, psi
);
1287 hitem
= treeitem_from_shellitem(This
, psi
);
1290 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (WPARAM
)hitem
);
1294 return E_INVALIDARG
;
1297 static HRESULT WINAPI
NSTC2_fnSetTheme(INameSpaceTreeControl2
* iface
,
1300 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1301 FIXME("stub, %p (%p)\n", This
, pszTheme
);
1305 static HRESULT WINAPI
NSTC2_fnGetNextItem(INameSpaceTreeControl2
* iface
,
1308 IShellItem
**ppsiNext
)
1310 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1311 HTREEITEM hitem
, hnext
;
1313 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcgi
, ppsiNext
);
1315 if(!ppsiNext
) return E_POINTER
;
1316 if(!psi
) return E_FAIL
;
1320 hitem
= treeitem_from_shellitem(This
, psi
);
1322 return E_INVALIDARG
;
1326 case NSTCGNI_NEXT
: tvgn
= TVGN_NEXT
; break;
1327 case NSTCGNI_NEXTVISIBLE
: tvgn
= TVGN_NEXTVISIBLE
; break;
1328 case NSTCGNI_PREV
: tvgn
= TVGN_PREVIOUS
; break;
1329 case NSTCGNI_PREVVISIBLE
: tvgn
= TVGN_PREVIOUSVISIBLE
; break;
1330 case NSTCGNI_PARENT
: tvgn
= TVGN_PARENT
; break;
1331 case NSTCGNI_CHILD
: tvgn
= TVGN_CHILD
; break;
1332 case NSTCGNI_FIRSTVISIBLE
: tvgn
= TVGN_FIRSTVISIBLE
; break;
1333 case NSTCGNI_LASTVISIBLE
: tvgn
= TVGN_LASTVISIBLE
; break;
1335 FIXME("Unknown nstcgi value %d\n", nstcgi
);
1339 hnext
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, tvgn
, (WPARAM
)hitem
);
1342 *ppsiNext
= shellitem_from_treeitem(This
, hnext
);
1343 IShellItem_AddRef(*ppsiNext
);
1350 static HRESULT WINAPI
NSTC2_fnHitTest(INameSpaceTreeControl2
* iface
,
1352 IShellItem
**ppsiOut
)
1354 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1356 TRACE("%p (%p, %p)\n", This
, ppsiOut
, ppt
);
1358 if(!ppt
|| !ppsiOut
)
1363 hitem
= treeitem_from_point(This
, ppt
, NULL
);
1365 *ppsiOut
= shellitem_from_treeitem(This
, hitem
);
1369 IShellItem_AddRef(*ppsiOut
);
1376 static HRESULT WINAPI
NSTC2_fnGetItemRect(INameSpaceTreeControl2
* iface
,
1380 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1382 TRACE("%p (%p, %p)\n", This
, psi
, prect
);
1387 hitem
= treeitem_from_shellitem(This
, psi
);
1390 *(HTREEITEM
*)prect
= hitem
;
1391 if(SendMessageW(This
->hwnd_tv
, TVM_GETITEMRECT
, FALSE
, (LPARAM
)prect
))
1393 MapWindowPoints(This
->hwnd_tv
, HWND_DESKTOP
, (POINT
*)prect
, 2);
1398 return E_INVALIDARG
;
1401 static HRESULT WINAPI
NSTC2_fnCollapseAll(INameSpaceTreeControl2
* iface
)
1403 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1405 TRACE("%p\n", This
);
1407 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1408 collapse_all(This
, root
->htreeitem
);
1413 static HRESULT WINAPI
NSTC2_fnSetControlStyle(INameSpaceTreeControl2
* iface
,
1414 NSTCSTYLE nstcsMask
,
1415 NSTCSTYLE nstcsStyle
)
1417 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1418 static const DWORD tv_style_flags
=
1419 NSTCS_HASEXPANDOS
| NSTCS_HASLINES
| NSTCS_FULLROWSELECT
|
1420 NSTCS_HORIZONTALSCROLL
| NSTCS_ROOTHASEXPANDO
|
1421 NSTCS_SHOWSELECTIONALWAYS
| NSTCS_NOINFOTIP
| NSTCS_EVENHEIGHT
|
1422 NSTCS_DISABLEDRAGDROP
| NSTCS_NOEDITLABELS
| NSTCS_CHECKBOXES
;
1423 static const DWORD host_style_flags
= NSTCS_TABSTOP
| NSTCS_BORDER
;
1424 static const DWORD nstc_flags
=
1425 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
|
1426 NSTCS_FAVORITESMODE
| NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
|
1427 NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
| NSTCS_SHOWREFRESHBUTTON
;
1428 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1430 /* Fail if there is an attempt to set an unknown style. */
1431 if(nstcsMask
& ~(tv_style_flags
| host_style_flags
| nstc_flags
))
1434 if(nstcsMask
& tv_style_flags
)
1437 treeview_style_from_nstcs(This
, nstcsStyle
, nstcsMask
, &new_style
);
1438 SetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
, new_style
);
1441 /* Flags affecting the host window */
1442 if(nstcsMask
& NSTCS_BORDER
)
1444 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
);
1445 new_style
&= ~WS_BORDER
;
1446 new_style
|= nstcsStyle
& NSTCS_BORDER
? WS_BORDER
: 0;
1447 SetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
, new_style
);
1449 if(nstcsMask
& NSTCS_TABSTOP
)
1451 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
);
1452 new_style
&= ~WS_EX_CONTROLPARENT
;
1453 new_style
|= nstcsStyle
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
1454 SetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
, new_style
);
1457 if((nstcsStyle
& nstcsMask
) & unsupported_styles
)
1458 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1459 (nstcsStyle
& nstcsMask
),
1460 (nstcsStyle
& nstcsMask
) & unsupported_styles
);
1462 This
->style
&= ~nstcsMask
;
1463 This
->style
|= (nstcsStyle
& nstcsMask
);
1468 static HRESULT WINAPI
NSTC2_fnGetControlStyle(INameSpaceTreeControl2
* iface
,
1469 NSTCSTYLE nstcsMask
,
1470 NSTCSTYLE
*pnstcsStyle
)
1472 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1473 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1475 *pnstcsStyle
= (This
->style
& nstcsMask
);
1480 static HRESULT WINAPI
NSTC2_fnSetControlStyle2(INameSpaceTreeControl2
* iface
,
1481 NSTCSTYLE2 nstcsMask
,
1482 NSTCSTYLE2 nstcsStyle
)
1484 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1485 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1487 if((nstcsStyle
& nstcsMask
) & unsupported_styles2
)
1488 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1489 (nstcsStyle
& nstcsMask
),
1490 (nstcsStyle
& nstcsMask
) & unsupported_styles2
);
1492 This
->style2
&= ~nstcsMask
;
1493 This
->style2
|= (nstcsStyle
& nstcsMask
);
1498 static HRESULT WINAPI
NSTC2_fnGetControlStyle2(INameSpaceTreeControl2
* iface
,
1499 NSTCSTYLE2 nstcsMask
,
1500 NSTCSTYLE2
*pnstcsStyle
)
1502 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1503 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1505 *pnstcsStyle
= (This
->style2
& nstcsMask
);
1510 static const INameSpaceTreeControl2Vtbl vt_INameSpaceTreeControl2
= {
1511 NSTC2_fnQueryInterface
,
1516 NSTC2_fnTreeUnadvise
,
1520 NSTC2_fnRemoveAllRoots
,
1521 NSTC2_fnGetRootItems
,
1522 NSTC2_fnSetItemState
,
1523 NSTC2_fnGetItemState
,
1524 NSTC2_fnGetSelectedItems
,
1525 NSTC2_fnGetItemCustomState
,
1526 NSTC2_fnSetItemCustomState
,
1527 NSTC2_fnEnsureItemVisible
,
1529 NSTC2_fnGetNextItem
,
1531 NSTC2_fnGetItemRect
,
1532 NSTC2_fnCollapseAll
,
1533 NSTC2_fnSetControlStyle
,
1534 NSTC2_fnGetControlStyle
,
1535 NSTC2_fnSetControlStyle2
,
1536 NSTC2_fnGetControlStyle2
1539 /**************************************************************************
1540 * IOleWindow Implementation
1543 static HRESULT WINAPI
IOW_fnQueryInterface(IOleWindow
*iface
, REFIID riid
, void **ppvObject
)
1545 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1546 return INameSpaceTreeControl2_QueryInterface(&This
->INameSpaceTreeControl2_iface
, riid
, ppvObject
);
1549 static ULONG WINAPI
IOW_fnAddRef(IOleWindow
*iface
)
1551 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1552 return INameSpaceTreeControl2_AddRef(&This
->INameSpaceTreeControl2_iface
);
1555 static ULONG WINAPI
IOW_fnRelease(IOleWindow
*iface
)
1557 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1558 return INameSpaceTreeControl2_Release(&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
= heap_alloc_zero(sizeof(*nstc
));
1603 return E_OUTOFMEMORY
;
1606 nstc
->INameSpaceTreeControl2_iface
.lpVtbl
= &vt_INameSpaceTreeControl2
;
1607 nstc
->IOleWindow_iface
.lpVtbl
= &vt_IOleWindow
;
1609 list_init(&nstc
->roots
);
1611 ret
= INameSpaceTreeControl2_QueryInterface(&nstc
->INameSpaceTreeControl2_iface
, riid
, ppv
);
1612 INameSpaceTreeControl2_Release(&nstc
->INameSpaceTreeControl2_iface
);
1614 TRACE("--(%p)\n", ppv
);