Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfonts.cpp
Go to the documentation of this file.
00001 /* 00002 * Fonts folder 00003 * 00004 * Copyright 2008 Johannes Anderwald <janderwald@reactos.org> 00005 * Copyright 2009 Andrew Hill 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include <precomp.h> 00023 00024 WINE_DEFAULT_DEBUG_CHANNEL (shell); 00025 00026 /* 00027 This folder should not exist. It is just a file system folder... The \windows\fonts 00028 directory contains a hidden desktop.ini with a UIHandler entry that specifies a class 00029 that lives in fontext.dll. The UI handler creates a custom view for the folder, which 00030 is what we normally see. However, the folder is a perfectly normal CFSFolder. 00031 */ 00032 00033 /*********************************************************************** 00034 * IShellFolder implementation 00035 */ 00036 00037 class CDesktopFolderEnumZ: public IEnumIDListImpl 00038 { 00039 public: 00040 CDesktopFolderEnumZ(); 00041 ~CDesktopFolderEnumZ(); 00042 HRESULT WINAPI Initialize(DWORD dwFlags); 00043 BOOL CreateFontsEnumList(DWORD dwFlags); 00044 00045 BEGIN_COM_MAP(CDesktopFolderEnumZ) 00046 COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) 00047 END_COM_MAP() 00048 }; 00049 00050 static shvheader FontsSFHeader[] = { 00051 {IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15}, 00052 {IDS_SHV_COLUMN_FONTTYPE , SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15}, 00053 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15}, 00054 {IDS_SHV_COLUMN12, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15} 00055 }; 00056 00057 #define COLUMN_NAME 0 00058 #define COLUMN_TYPE 1 00059 #define COLUMN_SIZE 2 00060 #define COLUMN_FILENAME 3 00061 00062 #define FontsSHELLVIEWCOLUMNS (4) 00063 00064 CDesktopFolderEnumZ::CDesktopFolderEnumZ() 00065 { 00066 } 00067 00068 CDesktopFolderEnumZ::~CDesktopFolderEnumZ() 00069 { 00070 } 00071 00072 HRESULT WINAPI CDesktopFolderEnumZ::Initialize(DWORD dwFlags) 00073 { 00074 if (CreateFontsEnumList(dwFlags) == FALSE) 00075 return E_FAIL; 00076 return S_OK; 00077 } 00078 00079 static LPITEMIDLIST _ILCreateFontItem(LPWSTR pszFont, LPWSTR pszFile) 00080 { 00081 PIDLDATA tmp; 00082 LPITEMIDLIST pidl; 00083 PIDLFontStruct * p; 00084 int size0 = (char*)&tmp.u.cfont.szName - (char*)&tmp.u.cfont; 00085 int size = size0; 00086 00087 tmp.type = 0x00; 00088 tmp.u.cfont.dummy = 0xFF; 00089 tmp.u.cfont.offsFile = wcslen(pszFont) + 1; 00090 00091 size += (tmp.u.cfont.offsFile + wcslen(pszFile) + 1) * sizeof(WCHAR); 00092 00093 pidl = (LPITEMIDLIST)SHAlloc(size + 4); 00094 if (!pidl) 00095 return pidl; 00096 00097 pidl->mkid.cb = size + 2; 00098 memcpy(pidl->mkid.abID, &tmp, 2 + size0); 00099 00100 p = &((PIDLDATA*)pidl->mkid.abID)->u.cfont; 00101 wcscpy(p->szName, pszFont); 00102 wcscpy(p->szName + tmp.u.cfont.offsFile, pszFile); 00103 00104 *(WORD*)((char*)pidl + (size + 2)) = 0; 00105 return pidl; 00106 } 00107 00108 static PIDLFontStruct * _ILGetFontStruct(LPCITEMIDLIST pidl) 00109 { 00110 LPPIDLDATA pdata = _ILGetDataPointer(pidl); 00111 00112 if (pdata && pdata->type == 0x00) 00113 return (PIDLFontStruct*) & (pdata->u.cfont); 00114 00115 return NULL; 00116 } 00117 00118 /************************************************************************** 00119 * CDesktopFolderEnumZ::CreateFontsEnumList() 00120 */ 00121 BOOL CDesktopFolderEnumZ::CreateFontsEnumList(DWORD dwFlags) 00122 { 00123 WCHAR szPath[MAX_PATH]; 00124 WCHAR szName[LF_FACESIZE+20]; 00125 WCHAR szFile[MAX_PATH]; 00126 LPWSTR pszPath; 00127 UINT Length; 00128 LONG ret; 00129 DWORD dwType, dwName, dwFile, dwIndex; 00130 LPITEMIDLIST pidl; 00131 HKEY hKey; 00132 00133 if (dwFlags & SHCONTF_NONFOLDERS) 00134 { 00135 if (!SHGetSpecialFolderPathW(NULL, szPath, CSIDL_FONTS, FALSE)) 00136 return FALSE; 00137 00138 pszPath = PathAddBackslashW(szPath); 00139 if (!pszPath) 00140 return FALSE; 00141 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", 0, KEY_READ, &hKey) != ERROR_SUCCESS) 00142 return FALSE; 00143 00144 Length = pszPath - szPath; 00145 dwIndex = 0; 00146 do 00147 { 00148 dwName = sizeof(szName) / sizeof(WCHAR); 00149 dwFile = sizeof(szFile) / sizeof(WCHAR); 00150 ret = RegEnumValueW(hKey, dwIndex++, szName, &dwName, NULL, &dwType, (LPBYTE)szFile, &dwFile); 00151 if (ret == ERROR_SUCCESS) 00152 { 00153 szFile[(sizeof(szFile)/sizeof(WCHAR))-1] = L'\0'; 00154 if (dwType == REG_SZ && wcslen(szFile) + Length + 1 < (sizeof(szPath) / sizeof(WCHAR))) 00155 { 00156 wcscpy(&szPath[Length], szFile); 00157 pidl = _ILCreateFontItem(szName, szPath); 00158 TRACE("pidl %p name %s path %s\n", pidl, debugstr_w(szName), debugstr_w(szPath)); 00159 if (pidl) 00160 { 00161 if (!AddToEnumList(pidl)) 00162 SHFree(pidl); 00163 } 00164 } 00165 } 00166 } while(ret != ERROR_NO_MORE_ITEMS); 00167 RegCloseKey(hKey); 00168 00169 } 00170 return TRUE; 00171 } 00172 00173 CFontsFolder::CFontsFolder() 00174 { 00175 pidlRoot = NULL; 00176 apidl = NULL; 00177 } 00178 00179 CFontsFolder::~CFontsFolder() 00180 { 00181 TRACE("-- destroying IShellFolder(%p)\n", this); 00182 SHFree(pidlRoot); 00183 } 00184 00185 HRESULT WINAPI CFontsFolder::FinalConstruct() 00186 { 00187 pidlRoot = _ILCreateFont(); /* my qualified pidl */ 00188 if (pidlRoot == NULL) 00189 return E_OUTOFMEMORY; 00190 return S_OK; 00191 } 00192 00193 /************************************************************************** 00194 * CFontsFolder::ParseDisplayName 00195 */ 00196 HRESULT WINAPI CFontsFolder::ParseDisplayName( 00197 HWND hwndOwner, 00198 LPBC pbcReserved, 00199 LPOLESTR lpszDisplayName, 00200 DWORD *pchEaten, 00201 LPITEMIDLIST *ppidl, 00202 DWORD * pdwAttributes) 00203 { 00204 HRESULT hr = E_UNEXPECTED; 00205 00206 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", this, 00207 hwndOwner, pbcReserved, lpszDisplayName, debugstr_w (lpszDisplayName), 00208 pchEaten, ppidl, pdwAttributes); 00209 00210 *ppidl = 0; 00211 if (pchEaten) 00212 *pchEaten = 0; /* strange but like the original */ 00213 00214 TRACE ("(%p)->(-- ret=0x%08x)\n", this, hr); 00215 00216 return hr; 00217 } 00218 00219 /************************************************************************** 00220 * CFontsFolder::EnumObjects 00221 */ 00222 HRESULT WINAPI CFontsFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList) 00223 { 00224 CComObject<CDesktopFolderEnumZ> *theEnumerator; 00225 CComPtr<IEnumIDList> result; 00226 HRESULT hResult; 00227 00228 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList); 00229 00230 if (ppEnumIDList == NULL) 00231 return E_POINTER; 00232 *ppEnumIDList = NULL; 00233 ATLTRY (theEnumerator = new CComObject<CDesktopFolderEnumZ>); 00234 if (theEnumerator == NULL) 00235 return E_OUTOFMEMORY; 00236 hResult = theEnumerator->QueryInterface (IID_IEnumIDList, (void **)&result); 00237 if (FAILED (hResult)) 00238 { 00239 delete theEnumerator; 00240 return hResult; 00241 } 00242 hResult = theEnumerator->Initialize (dwFlags); 00243 if (FAILED (hResult)) 00244 return hResult; 00245 *ppEnumIDList = result.Detach (); 00246 00247 TRACE ("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList); 00248 00249 return S_OK; 00250 } 00251 00252 /************************************************************************** 00253 * CFontsFolder::BindToObject 00254 */ 00255 HRESULT WINAPI CFontsFolder::BindToObject(LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut) 00256 { 00257 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", this, 00258 pidl, pbcReserved, shdebugstr_guid (&riid), ppvOut); 00259 00260 return SHELL32_BindToChild (pidlRoot, NULL, pidl, riid, ppvOut); 00261 } 00262 00263 /************************************************************************** 00264 * CFontsFolder::BindToStorage 00265 */ 00266 HRESULT WINAPI CFontsFolder::BindToStorage(LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut) 00267 { 00268 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", this, 00269 pidl, pbcReserved, shdebugstr_guid (&riid), ppvOut); 00270 00271 *ppvOut = NULL; 00272 return E_NOTIMPL; 00273 } 00274 00275 /************************************************************************** 00276 * CFontsFolder::CompareIDs 00277 */ 00278 00279 HRESULT WINAPI CFontsFolder::CompareIDs(LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) 00280 { 00281 int nReturn; 00282 00283 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", this, lParam, pidl1, pidl2); 00284 nReturn = SHELL32_CompareIDs (this, lParam, pidl1, pidl2); 00285 TRACE ("-- %i\n", nReturn); 00286 return nReturn; 00287 } 00288 00289 /************************************************************************** 00290 * CFontsFolder::CreateViewObject 00291 */ 00292 HRESULT WINAPI CFontsFolder::CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut) 00293 { 00294 CComPtr<IShellView> pShellView; 00295 HRESULT hr = E_INVALIDARG; 00296 00297 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", this, 00298 hwndOwner, shdebugstr_guid (&riid), ppvOut); 00299 00300 if (!ppvOut) 00301 return hr; 00302 00303 *ppvOut = NULL; 00304 00305 if (IsEqualIID (riid, IID_IDropTarget)) 00306 { 00307 WARN ("IDropTarget not implemented\n"); 00308 hr = E_NOTIMPL; 00309 } 00310 else if (IsEqualIID (riid, IID_IContextMenu)) 00311 { 00312 WARN ("IContextMenu not implemented\n"); 00313 hr = E_NOTIMPL; 00314 } 00315 else if (IsEqualIID (riid, IID_IShellView)) 00316 { 00317 hr = IShellView_Constructor ((IShellFolder *)this, &pShellView); 00318 if (pShellView) 00319 hr = pShellView->QueryInterface(riid, ppvOut); 00320 } 00321 TRACE ("-- (%p)->(interface=%p)\n", this, ppvOut); 00322 return hr; 00323 } 00324 00325 /************************************************************************** 00326 * CFontsFolder::GetAttributesOf 00327 */ 00328 HRESULT WINAPI CFontsFolder::GetAttributesOf(UINT cidl, LPCITEMIDLIST *apidl, DWORD *rgfInOut) 00329 { 00330 HRESULT hr = S_OK; 00331 00332 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", this, 00333 cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0); 00334 00335 if (!rgfInOut) 00336 return E_INVALIDARG; 00337 if (cidl && !apidl) 00338 return E_INVALIDARG; 00339 00340 if (*rgfInOut == 0) 00341 *rgfInOut = ~0; 00342 00343 if (cidl == 0) 00344 { 00345 CComPtr<IShellFolder> psfParent; 00346 LPCITEMIDLIST rpidl = NULL; 00347 00348 hr = SHBindToParent(pidlRoot, IID_IShellFolder, (LPVOID *)&psfParent, (LPCITEMIDLIST *)&rpidl); 00349 if (SUCCEEDED(hr)) 00350 SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut); 00351 } 00352 else 00353 { 00354 while (cidl > 0 && *apidl) 00355 { 00356 pdump (*apidl); 00357 SHELL32_GetItemAttributes (this, *apidl, rgfInOut); 00358 apidl++; 00359 cidl--; 00360 } 00361 } 00362 00363 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */ 00364 *rgfInOut &= ~SFGAO_VALIDATE; 00365 00366 TRACE ("-- result=0x%08x\n", *rgfInOut); 00367 return hr; 00368 } 00369 00370 /************************************************************************** 00371 * CFontsFolder::GetUIObjectOf 00372 * 00373 * PARAMETERS 00374 * hwndOwner [in] Parent window for any output 00375 * cidl [in] array size 00376 * apidl [in] simple pidl array 00377 * riid [in] Requested Interface 00378 * prgfInOut [ ] reserved 00379 * ppvObject [out] Resulting Interface 00380 * 00381 */ 00382 HRESULT WINAPI CFontsFolder::GetUIObjectOf( 00383 HWND hwndOwner, 00384 UINT cidl, LPCITEMIDLIST *apidl, 00385 REFIID riid, UINT *prgfInOut, LPVOID *ppvOut) 00386 { 00387 LPITEMIDLIST pidl; 00388 CComPtr<IUnknown> pObj; 00389 HRESULT hr = E_INVALIDARG; 00390 00391 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", this, 00392 hwndOwner, cidl, apidl, shdebugstr_guid (&riid), prgfInOut, ppvOut); 00393 00394 if (!ppvOut) 00395 return hr; 00396 00397 *ppvOut = NULL; 00398 00399 if (IsEqualIID (riid, IID_IContextMenu) && (cidl >= 1)) 00400 { 00401 pObj = (IContextMenu *)this; 00402 this->apidl = apidl[0]; 00403 hr = S_OK; 00404 } 00405 else if (IsEqualIID (riid, IID_IDataObject) && (cidl >= 1)) 00406 { 00407 hr = IDataObject_Constructor (hwndOwner, pidlRoot, apidl, cidl, (IDataObject **)&pObj); 00408 } 00409 else if (IsEqualIID (riid, IID_IExtractIconA) && (cidl == 1)) 00410 { 00411 pidl = ILCombine (pidlRoot, apidl[0]); 00412 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl); 00413 SHFree (pidl); 00414 hr = S_OK; 00415 } 00416 else if (IsEqualIID (riid, IID_IExtractIconW) && (cidl == 1)) 00417 { 00418 pidl = ILCombine (pidlRoot, apidl[0]); 00419 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl); 00420 SHFree (pidl); 00421 hr = S_OK; 00422 } 00423 else if (IsEqualIID (riid, IID_IDropTarget) && (cidl >= 1)) 00424 { 00425 hr = this->QueryInterface(IID_IDropTarget, (LPVOID *) & pObj); 00426 } 00427 else 00428 hr = E_NOINTERFACE; 00429 00430 if (SUCCEEDED(hr) && !pObj) 00431 hr = E_OUTOFMEMORY; 00432 00433 *ppvOut = pObj.Detach(); 00434 TRACE ("(%p)->hr=0x%08x\n", this, hr); 00435 return hr; 00436 } 00437 00438 /************************************************************************** 00439 * CFontsFolder::GetDisplayNameOf 00440 * 00441 */ 00442 HRESULT WINAPI CFontsFolder::GetDisplayNameOf(LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet) 00443 { 00444 PIDLFontStruct *pFont; 00445 00446 TRACE("(%p)->(pidl=%p,0x%08x,%p)\n", this, pidl, dwFlags, strRet); 00447 pdump (pidl); 00448 00449 if (!strRet) 00450 return E_INVALIDARG; 00451 00452 pFont = _ILGetFontStruct(pidl); 00453 if (pFont) 00454 { 00455 strRet->pOleStr = (LPWSTR)CoTaskMemAlloc((wcslen(pFont->szName) + 1) * sizeof(WCHAR)); 00456 if (!strRet->pOleStr) 00457 return E_OUTOFMEMORY; 00458 00459 wcscpy(strRet->pOleStr, pFont->szName); 00460 strRet->uType = STRRET_WSTR; 00461 } 00462 else if (!pidl->mkid.cb) 00463 { 00464 WCHAR wszPath[MAX_PATH]; 00465 00466 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && 00467 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)) 00468 { 00469 if (!SHGetSpecialFolderPathW(NULL, wszPath, CSIDL_FONTS, FALSE)) 00470 return E_FAIL; 00471 } 00472 else if (!HCR_GetClassNameW(CLSID_FontsFolderShortcut, wszPath, MAX_PATH)) 00473 return E_FAIL; 00474 00475 strRet->pOleStr = (LPWSTR)CoTaskMemAlloc((wcslen(wszPath) + 1) * sizeof(WCHAR)); 00476 if (!strRet->pOleStr) 00477 return E_OUTOFMEMORY; 00478 00479 wcscpy(strRet->pOleStr, wszPath); 00480 strRet->uType = STRRET_WSTR; 00481 } 00482 else 00483 return E_INVALIDARG; 00484 00485 return S_OK; 00486 } 00487 00488 /************************************************************************** 00489 * CFontsFolder::SetNameOf 00490 * Changes the name of a file object or subfolder, possibly changing its item 00491 * identifier in the process. 00492 * 00493 * PARAMETERS 00494 * hwndOwner [in] Owner window for output 00495 * pidl [in] simple pidl of item to change 00496 * lpszName [in] the items new display name 00497 * dwFlags [in] SHGNO formatting flags 00498 * ppidlOut [out] simple pidl returned 00499 */ 00500 HRESULT WINAPI CFontsFolder::SetNameOf(HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */ 00501 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut) 00502 { 00503 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", this, 00504 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut); 00505 return E_FAIL; 00506 } 00507 00508 HRESULT WINAPI CFontsFolder::GetDefaultSearchGUID(GUID *pguid) 00509 { 00510 FIXME ("(%p)\n", this); 00511 return E_NOTIMPL; 00512 } 00513 00514 HRESULT WINAPI CFontsFolder::EnumSearches(IEnumExtraSearch **ppenum) 00515 { 00516 FIXME ("(%p)\n", this); 00517 return E_NOTIMPL; 00518 } 00519 00520 HRESULT WINAPI CFontsFolder::GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay) 00521 { 00522 TRACE ("(%p)\n", this); 00523 00524 if (pSort) 00525 *pSort = 0; 00526 if (pDisplay) 00527 *pDisplay = 0; 00528 00529 return S_OK; 00530 } 00531 00532 HRESULT WINAPI CFontsFolder::GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags) 00533 { 00534 TRACE ("(%p)\n", this); 00535 00536 if (!pcsFlags || iColumn >= FontsSHELLVIEWCOLUMNS) 00537 return E_INVALIDARG; 00538 *pcsFlags = FontsSFHeader[iColumn].pcsFlags; 00539 return S_OK; 00540 } 00541 00542 HRESULT WINAPI CFontsFolder::GetDetailsEx(LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv) 00543 { 00544 FIXME ("(%p)\n", this); 00545 return E_NOTIMPL; 00546 } 00547 00548 HRESULT WINAPI CFontsFolder::GetDetailsOf(LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd) 00549 { 00550 WCHAR buffer[MAX_PATH] = {0}; 00551 HRESULT hr = E_FAIL; 00552 PIDLFontStruct * pfont; 00553 HANDLE hFile; 00554 LARGE_INTEGER FileSize; 00555 SHFILEINFOW fi; 00556 00557 TRACE("(%p, %p, %d, %p)\n", this, pidl, iColumn, psd); 00558 00559 if (iColumn >= FontsSHELLVIEWCOLUMNS) 00560 return E_FAIL; 00561 00562 psd->fmt = FontsSFHeader[iColumn].fmt; 00563 psd->cxChar = FontsSFHeader[iColumn].cxChar; 00564 if (pidl == NULL) 00565 { 00566 psd->str.uType = STRRET_WSTR; 00567 if (LoadStringW(shell32_hInstance, FontsSFHeader[iColumn].colnameid, buffer, MAX_PATH)) 00568 hr = SHStrDupW(buffer, &psd->str.pOleStr); 00569 00570 return hr; 00571 } 00572 00573 if (iColumn == COLUMN_NAME) 00574 { 00575 psd->str.uType = STRRET_WSTR; 00576 return GetDisplayNameOf(pidl, SHGDN_NORMAL, &psd->str); 00577 } 00578 00579 psd->str.uType = STRRET_CSTR; 00580 psd->str.cStr[0] = '\0'; 00581 00582 switch(iColumn) 00583 { 00584 case COLUMN_TYPE: 00585 pfont = _ILGetFontStruct(pidl); 00586 if (pfont) 00587 { 00588 if (SHGetFileInfoW(pfont->szName + pfont->offsFile, 0, &fi, sizeof(fi), SHGFI_TYPENAME)) 00589 { 00590 psd->str.pOleStr = (LPWSTR)CoTaskMemAlloc((wcslen(fi.szTypeName) + 1) * sizeof(WCHAR)); 00591 if (!psd->str.pOleStr) 00592 return E_OUTOFMEMORY; 00593 wcscpy(psd->str.pOleStr, fi.szTypeName); 00594 psd->str.uType = STRRET_WSTR; 00595 return S_OK; 00596 } 00597 } 00598 break; 00599 case COLUMN_SIZE: 00600 pfont = _ILGetFontStruct(pidl); 00601 if (pfont) 00602 { 00603 hFile = CreateFileW(pfont->szName + pfont->offsFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 00604 if (hFile != INVALID_HANDLE_VALUE) 00605 { 00606 if (GetFileSizeEx(hFile, &FileSize)) 00607 { 00608 if (StrFormatByteSizeW(FileSize.QuadPart, buffer, sizeof(buffer) / sizeof(WCHAR))) 00609 { 00610 psd->str.pOleStr = (LPWSTR)CoTaskMemAlloc(wcslen(buffer) + 1); 00611 if (!psd->str.pOleStr) 00612 return E_OUTOFMEMORY; 00613 wcscpy(psd->str.pOleStr, buffer); 00614 psd->str.uType = STRRET_WSTR; 00615 CloseHandle(hFile); 00616 return S_OK; 00617 } 00618 } 00619 CloseHandle(hFile); 00620 } 00621 } 00622 break; 00623 case COLUMN_FILENAME: 00624 pfont = _ILGetFontStruct(pidl); 00625 if (pfont) 00626 { 00627 psd->str.pOleStr = (LPWSTR)CoTaskMemAlloc((wcslen(pfont->szName + pfont->offsFile) + 1) * sizeof(WCHAR)); 00628 if (psd->str.pOleStr) 00629 { 00630 psd->str.uType = STRRET_WSTR; 00631 wcscpy(psd->str.pOleStr, pfont->szName + pfont->offsFile); 00632 return S_OK; 00633 } 00634 else 00635 return E_OUTOFMEMORY; 00636 } 00637 break; 00638 } 00639 00640 return E_FAIL; 00641 } 00642 00643 HRESULT WINAPI CFontsFolder::MapColumnToSCID(UINT column, SHCOLUMNID *pscid) 00644 { 00645 FIXME ("(%p)\n", this); 00646 00647 return E_NOTIMPL; 00648 } 00649 00650 /************************************************************************ 00651 * CFontsFolder::GetClassID 00652 */ 00653 HRESULT WINAPI CFontsFolder::GetClassID(CLSID *lpClassId) 00654 { 00655 TRACE ("(%p)\n", this); 00656 00657 if (!lpClassId) 00658 return E_POINTER; 00659 00660 *lpClassId = CLSID_FontsFolderShortcut; 00661 00662 return S_OK; 00663 } 00664 00665 /************************************************************************ 00666 * CFontsFolder::Initialize 00667 * 00668 * NOTES: it makes no sense to change the pidl 00669 */ 00670 HRESULT WINAPI CFontsFolder::Initialize(LPCITEMIDLIST pidl) 00671 { 00672 TRACE ("(%p)->(%p)\n", this, pidl); 00673 00674 return E_NOTIMPL; 00675 } 00676 00677 /************************************************************************** 00678 * CFontsFolder::GetCurFolder 00679 */ 00680 HRESULT WINAPI CFontsFolder::GetCurFolder(LPITEMIDLIST *pidl) 00681 { 00682 TRACE ("(%p)->(%p)\n", this, pidl); 00683 00684 if (!pidl) 00685 return E_POINTER; 00686 00687 *pidl = ILClone(pidlRoot); 00688 00689 return S_OK; 00690 } 00691 00692 /************************************************************************** 00693 * IContextMenu2 Implementation 00694 */ 00695 00696 /************************************************************************** 00697 * CFontsFolder::QueryContextMenu() 00698 */ 00699 HRESULT WINAPI CFontsFolder::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) 00700 { 00701 WCHAR szBuffer[30] = {0}; 00702 ULONG Count = 1; 00703 00704 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n", 00705 this, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags); 00706 00707 if (LoadStringW(shell32_hInstance, IDS_OPEN, szBuffer, sizeof(szBuffer) / sizeof(WCHAR))) 00708 { 00709 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0'; 00710 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count, MFT_STRING, szBuffer, MFS_DEFAULT); 00711 Count++; 00712 } 00713 00714 if (LoadStringW(shell32_hInstance, IDS_PRINT_VERB, szBuffer, sizeof(szBuffer) / sizeof(WCHAR))) 00715 { 00716 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0'; 00717 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_STRING, szBuffer, MFS_ENABLED); 00718 } 00719 00720 if (LoadStringW(shell32_hInstance, IDS_COPY, szBuffer, sizeof(szBuffer) / sizeof(WCHAR))) 00721 { 00722 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0'; 00723 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_SEPARATOR, NULL, MFS_ENABLED); 00724 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_STRING, szBuffer, MFS_ENABLED); 00725 } 00726 00727 if (LoadStringW(shell32_hInstance, IDS_DELETE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR))) 00728 { 00729 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0'; 00730 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_SEPARATOR, NULL, MFS_ENABLED); 00731 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count, MFT_STRING, szBuffer, MFS_ENABLED); 00732 } 00733 00734 if (LoadStringW(shell32_hInstance, IDS_PROPERTIES, szBuffer, sizeof(szBuffer) / sizeof(WCHAR))) 00735 { 00736 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0'; 00737 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_SEPARATOR, NULL, MFS_ENABLED); 00738 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count, MFT_STRING, szBuffer, MFS_ENABLED); 00739 } 00740 00741 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, Count); 00742 } 00743 00744 /************************************************************************** 00745 * CFontsFolder::InvokeCommand() 00746 */ 00747 HRESULT WINAPI CFontsFolder::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) 00748 { 00749 SHELLEXECUTEINFOW sei; 00750 PIDLFontStruct * pfont; 00751 SHFILEOPSTRUCTW op; 00752 00753 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n", this, lpcmi, lpcmi->lpVerb, lpcmi->hwnd); 00754 00755 if (lpcmi->lpVerb == MAKEINTRESOURCEA(1) || lpcmi->lpVerb == MAKEINTRESOURCEA(2) || lpcmi->lpVerb == MAKEINTRESOURCEA(7)) 00756 { 00757 ZeroMemory(&sei, sizeof(sei)); 00758 sei.cbSize = sizeof(sei); 00759 sei.hwnd = lpcmi->hwnd; 00760 sei.nShow = SW_SHOWNORMAL; 00761 if (lpcmi->lpVerb == MAKEINTRESOURCEA(1)) 00762 sei.lpVerb = L"open"; 00763 else if (lpcmi->lpVerb == MAKEINTRESOURCEA(2)) 00764 sei.lpVerb = L"print"; 00765 else if (lpcmi->lpVerb == MAKEINTRESOURCEA(7)) 00766 sei.lpVerb = L"properties"; 00767 00768 pfont = _ILGetFontStruct(apidl); 00769 sei.lpFile = pfont->szName + pfont->offsFile; 00770 00771 if (ShellExecuteExW(&sei) == FALSE) 00772 return E_FAIL; 00773 } 00774 else if (lpcmi->lpVerb == MAKEINTRESOURCEA(4)) 00775 { 00776 FIXME("implement font copying\n"); 00777 return E_NOTIMPL; 00778 } 00779 else if (lpcmi->lpVerb == MAKEINTRESOURCEA(6)) 00780 { 00781 ZeroMemory(&op, sizeof(op)); 00782 op.hwnd = lpcmi->hwnd; 00783 op.wFunc = FO_DELETE; 00784 op.fFlags = FOF_ALLOWUNDO; 00785 pfont = _ILGetFontStruct(apidl); 00786 op.pFrom = pfont->szName + pfont->offsFile; 00787 SHFileOperationW(&op); 00788 } 00789 00790 return S_OK; 00791 } 00792 00793 /************************************************************************** 00794 * CFontsFolder::GetCommandString() 00795 * 00796 */ 00797 HRESULT WINAPI CFontsFolder::GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen) 00798 { 00799 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n", this, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen); 00800 00801 return E_FAIL; 00802 } 00803 00804 /************************************************************************** 00805 * CFontsFolder::HandleMenuMsg() 00806 */ 00807 HRESULT WINAPI CFontsFolder::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) 00808 { 00809 TRACE("(%p)->(msg=%x wp=%lx lp=%lx)\n", this, uMsg, wParam, lParam); 00810 00811 return E_NOTIMPL; 00812 } Generated on Sun May 27 2012 04:26:21 for ReactOS by
1.7.6.1
|