ReactOS  0.4.15-dev-5146-g069b08d
CDeskLinkDropHandler.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: sendmail
3  * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE: DeskLink implementation
5  * COPYRIGHT: Copyright 2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  */
7 
8 #include "precomp.hpp"
9 
11 
13 {
15 }
16 
18 {
20 }
21 
22 // IDropTarget
25  POINTL pt, DWORD *pdwEffect)
26 {
27  TRACE("(%p)\n", this);
28 
29  *pdwEffect &= DROPEFFECT_LINK;
30 
31  return S_OK;
32 }
33 
36 {
37  TRACE("(%p)\n", this);
38 
39  *pdwEffect &= DROPEFFECT_LINK;
40 
41  return S_OK;
42 }
43 
45 {
46  TRACE("(%p)\n", this);
47  return S_OK;
48 }
49 
51 CDeskLinkDropHandler::Drop(IDataObject *pDataObject, DWORD dwKeyState,
52  POINTL pt, DWORD *pdwEffect)
53 {
54  TRACE("(%p)\n", this);
55 
56  if (!pDataObject)
57  {
58  ERR("pDataObject is NULL\n");
59  return E_POINTER;
60  }
61 
62  WCHAR szDir[MAX_PATH], szDest[MAX_PATH], szSrc[MAX_PATH];
64 
65  CComPtr<IShellFolder> pDesktop;
66  HRESULT hr = SHGetDesktopFolder(&pDesktop);
68  return hr;
69 
70  CDataObjectHIDA pida(pDataObject);
71  if (FAILED_UNEXPECTEDLY(pida.hr()))
72  return pida.hr();
73 
74  LPCITEMIDLIST pidlParent = HIDA_GetPIDLFolder(pida);
75  for (UINT i = 0; i < pida->cidl; ++i)
76  {
77  LPCITEMIDLIST pidlChild = HIDA_GetPIDLItem(pida, i);
78 
79  CComHeapPtr<ITEMIDLIST> pidl(ILCombine(pidlParent, pidlChild));
80  if (!pidl)
81  {
82  ERR("Out of memory\n");
83  break;
84  }
85 
86  StringCbCopyW(szDest, sizeof(szDest), szDir);
87  if (SHGetPathFromIDListW(pidl, szSrc))
88  {
89  CStringW strTitle;
90  strTitle.Format(IDS_SHORTCUT, PathFindFileNameW(szSrc));
91 
92  PathAppendW(szDest, strTitle);
93  PathRemoveExtensionW(szDest);
94  StringCbCatW(szDest, sizeof(szDest), L".lnk");
95 
96  hr = CreateShellLink(szDest, szSrc, NULL, NULL, NULL, NULL, -1, NULL);
97  }
98  else
99  {
100  STRRET strret;
101  hr = pDesktop->GetDisplayNameOf(pidl, SHGDN_INFOLDER, &strret);
102  if (FAILED_UNEXPECTEDLY(hr))
103  break;
104 
105  hr = StrRetToBufW(&strret, pidl, szSrc, _countof(szSrc));
106  if (FAILED_UNEXPECTEDLY(hr))
107  break;
108 
109  CStringW strTitle;
110  strTitle.Format(IDS_SHORTCUT, szSrc);
111 
112  PathAppendW(szDest, strTitle);
113  PathRemoveExtensionW(szDest);
114  StringCbCatW(szDest, sizeof(szDest), L".lnk");
115 
116  hr = CreateShellLink(szDest, NULL, pidl, NULL, NULL, NULL, -1, NULL);
117  }
118 
119  if (FAILED_UNEXPECTEDLY(hr))
120  break;
121  }
122 
123  return hr;
124 }
125 
126 // IPersistFile
128 {
129  FIXME("(%p)\n", this);
130  return E_NOTIMPL;
131 }
132 
134 {
135  FIXME("(%p)\n", this);
136  return E_NOTIMPL;
137 }
138 
140 {
141  return S_OK;
142 }
143 
145 {
146  FIXME("(%p)\n", this);
147  return E_NOTIMPL;
148 }
149 
151 {
152  FIXME("(%p)\n", this);
153  return E_NOTIMPL;
154 }
155 
156 // IPersist
158 {
159  TRACE("(%p)\n", this);
160 
161  if (!lpClassId)
162  {
163  ERR("lpClassId is NULL\n");
164  return E_POINTER;
165  }
166 
167  *lpClassId = CLSID_DeskLinkDropHandler;
168 
169  return S_OK;
170 }
HRESULT hr
Definition: shlfolder.c:183
#define pt(x, y)
Definition: drawing.c:79
LONG g_ModuleRefCnt
Definition: ACPPage.cpp:13
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1522
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:554
STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName)
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:753
#define IDS_SHORTCUT
Definition: resource.h:12
static LPOLESTR
Definition: stg_prop.c:27
STDMETHODIMP Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:126
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:823
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:111
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
#define STDMETHODIMP
Definition: basetyps.h:43
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
STDMETHODIMP DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:82
#define MAX_PATH
Definition: compat.h:34
const DWORD DROPEFFECT_LINK
Definition: oleidl.idl:932
unsigned long DWORD
Definition: ntddk_ex.h:95
#define InterlockedDecrement
Definition: armddk.h:52
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:549
STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember)
WINE_DEFAULT_DEBUG_CHANNEL(sendmail)
STDMETHODIMP GetClassID(CLSID *lpClassId)
#define ERR(fmt,...)
Definition: debug.h:110
STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode)
#define S_OK
Definition: intsafe.h:52
STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName)
#define InterlockedIncrement
Definition: armddk.h:53
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:2851
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT CreateShellLink(LPCWSTR pszLinkPath, LPCWSTR pszTargetPath OPTIONAL, LPCITEMIDLIST pidlTarget OPTIONAL, LPCWSTR pszArg OPTIONAL, LPCWSTR pszDir OPTIONAL, LPCWSTR pszIconPath OPTIONAL, INT iIconNr OPTIONAL, LPCWSTR pszComment OPTIONAL)
Definition: sendmail.cpp:102
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
STDMETHODIMP DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
#define CSIDL_DESKTOPDIRECTORY
Definition: shlobj.h:2027
#define E_POINTER
Definition: winerror.h:2365
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166