ReactOS 0.4.16-dev-1106-g00b5dc8
precomp.h File Reference
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <tchar.h>
#include <strsafe.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlcoll.h>
#include <atlstr.h>
#include <wine/debug.h>
#include <shellutils.h>
#include "resource.h"
#include "fontpidl.hpp"
#include "CFontCache.hpp"
#include "CFontExt.hpp"
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define COM_NO_WINDOWS_H
 
#define FONT_HIVE   HKEY_LOCAL_MACHINE
 
#define FONT_KEY   L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
 

Functions

HRESULT _CEnumFonts_CreateInstance (CFontExt *zip, DWORD flags, REFIID riid, LPVOID *ppvOut)
 
HRESULT _CFontMenu_CreateInstance (HWND hwnd, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IShellFolder *psf, REFIID riid, LPVOID *ppvOut)
 
HRESULT _CDataObject_CreateInstance (PCIDLIST_ABSOLUTE folder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, LPVOID *ppvOut)
 
BOOL IsFontDotExt (LPCWSTR pchDotExt)
 
HRESULT InstallFontFiles (_Out_ CStringW &strMessage, _In_ PCUIDLIST_ABSOLUTE pidlParent, _In_ UINT cidl, _In_ PCUITEMID_CHILD_ARRAY apidl)
 
HRESULT DoInstallFontFile (_Out_ CStringW &strMsg, _In_ PCWSTR pszFontPath, _In_ PCWSTR pszFontsDir, _In_ HKEY hkeyFonts)
 
HRESULT DoGetFontTitle (_In_ PCWSTR pszFontPath, _Out_ CStringW &strFontName)
 

Variables

const GUID CLSID_CFontExt
 
LONG g_ModuleRefCnt
 

Macro Definition Documentation

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 11 of file precomp.h.

◆ FONT_HIVE

#define FONT_HIVE   HKEY_LOCAL_MACHINE

Definition at line 35 of file precomp.h.

◆ FONT_KEY

#define FONT_KEY   L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"

Definition at line 36 of file precomp.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file precomp.h.

Function Documentation

◆ _CDataObject_CreateInstance()

HRESULT _CDataObject_CreateInstance ( PCIDLIST_ABSOLUTE  folder,
UINT  cidl,
PCUITEMID_CHILD_ARRAY  apidl,
REFIID  riid,
LPVOID ppvOut 
)

Definition at line 36 of file CDataObject.cpp.

38{
39 HRESULT hr = CIDLData_CreateFromIDArray(folder, cidl, apidl, (IDataObject**)ppvOut);
41 return hr;
42
43 // Now that we have an IDataObject with the shell itemid list (CFSTR_SHELLIDLIST, aka HIDA) format
44 // we will augment this IDataObject with the CF_HDROP format. (Full filepaths)
45 // This enabled the objects for the 'copy' and drag to copy actions
46
48
49 // First we allocate room for the DROPFILES structure
50 data.AllocateBytes(sizeof(DROPFILES));
51 UINT offset = sizeof(DROPFILES);
52
53 // Then we walk all files
54 for (UINT n = 0; n < cidl; ++n)
55 {
56 const FontPidlEntry* fontEntry = _FontFromIL(apidl[n]);
57 if (fontEntry)
58 {
59 CStringW File = g_FontCache->Filename(g_FontCache->Find(fontEntry), true);
60 if (!File.IsEmpty())
61 {
62 // Now append the path (+ nullterminator) to the buffer
63 UINT len = offset + (File.GetLength() + 1) * sizeof(WCHAR);
64 data.ReallocateBytes(len);
65 if (!data)
66 {
67 ERR("Unable to allocate memory for the CF_HDROP\n");
68 return hr;
69 }
70 BYTE* dataPtr = data;
72 offset = len;
73 }
74 else
75 {
76 ERR("No file found for %S\n", fontEntry->Name);
77 }
78 }
79 }
80
81 // Append the final nullterminator (double null terminated list)
82 data.ReallocateBytes(offset + sizeof(UNICODE_NULL));
85 offset += sizeof(UNICODE_NULL);
86
87 // Fill in the required fields
88 DROPFILES* pDrop = (DROPFILES*)(BYTE*)data;
89 pDrop->fWide = 1;
90 pDrop->pFiles = sizeof(DROPFILES);
91 // Zero out the rest
92 pDrop->pt.x = pDrop->pt.y = 0;
93 pDrop-> fNC = NULL;
94
97
98 return hr;
99}
CFontCache * g_FontCache
Definition: CFontCache.cpp:12
#define CF_HDROP
Definition: constants.h:410
#define ERR(fmt,...)
Definition: precomp.h:57
CStringW Filename(CFontInfo *info, bool alwaysFullPath=false)
Definition: CFontCache.cpp:164
CFontInfo * Find(const FontPidlEntry *fontEntry)
Definition: CFontCache.cpp:145
Definition: File.h:16
#define NULL
Definition: types.h:112
static HRESULT WINAPI DataObject_SetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
Definition: view.c:203
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:65
const FontPidlEntry * _FontFromIL(LPCITEMIDLIST pidl)
Definition: fontpidl.cpp:31
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
GLintptr offset
Definition: glext.h:5920
GLenum GLsizei len
Definition: glext.h:6722
unsigned int UINT
Definition: ndis.h:50
#define UNICODE_NULL
wchar_t * STRSAFE_LPWSTR
Definition: ntstrsafe.h:53
const WCHAR * str
HRESULT WINAPI CIDLData_CreateFromIDArray(PCIDLIST_ABSOLUTE pidlFolder, UINT cpidlFiles, PCUIDLIST_RELATIVE_ARRAY lppidlFiles, LPDATAOBJECT *ppdataObject)
Definition: shellord.c:2419
HRESULT hr
Definition: shlfolder.c:183
struct _DROPFILES DROPFILES
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
WCHAR Name[1]
Definition: fontpidl.hpp:17
DWORD pFiles
Definition: shlobj.h:2315
BOOL fWide
Definition: shlobj.h:2318
POINT pt
Definition: shlobj.h:2316
Definition: fci.c:116
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193

Referenced by CFontExt::GetUIObjectOf().

◆ _CEnumFonts_CreateInstance()

HRESULT _CEnumFonts_CreateInstance ( CFontExt zip,
DWORD  flags,
REFIID  riid,
LPVOID ppvOut 
)

Definition at line 97 of file CEnumFonts.cpp.

98{
99 return ShellObjectCreatorInit<CEnumFonts>(zip, flags, riid, ppvOut);
100}
GLbitfield flags
Definition: glext.h:7161
REFIID riid
Definition: atlbase.h:39

Referenced by CFontExt::EnumObjects().

◆ _CFontMenu_CreateInstance()

HRESULT _CFontMenu_CreateInstance ( HWND  hwnd,
UINT  cidl,
PCUITEMID_CHILD_ARRAY  apidl,
IShellFolder psf,
REFIID  riid,
LPVOID ppvOut 
)

Definition at line 111 of file CFontMenu.cpp.

113{
114 if (cidl > 0)
115 {
116 HKEY keys[1] = {0};
117 int nkeys = 0;
119
120 // Use the default context menu handler, but augment it from the callbacks
121 HRESULT hr = CDefFolderMenu_Create2(NULL, hwnd, cidl, apidl, psf, FontFolderMenuCallback, nkeys, keys, &spMenu);
122
124 return hr;
125
126 // See if the requested interface (e.g. IContextMenu3) is also available
127 return spMenu->QueryInterface(riid, ppvOut);
128 }
129
130 // We can't create a background menu
131 return E_FAIL;
132}
HRESULT WINAPI CDefFolderMenu_Create2(PCIDLIST_ABSOLUTE pidlFolder, HWND hwnd, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IShellFolder *psf, LPFNDFMCALLBACK lpfn, UINT nKeys, const HKEY *ahkeyClsKeys, IContextMenu **ppcm)
static HRESULT CALLBACK FontFolderMenuCallback(IShellFolder *psf, HWND hwnd, IDataObject *pdtobj, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: CFontMenu.cpp:55
#define E_FAIL
Definition: ddrawi.h:102
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by CFontExt::GetUIObjectOf().

◆ DoGetFontTitle()

HRESULT DoGetFontTitle ( _In_ PCWSTR  pszFontPath,
_Out_ CStringW strFontName 
)

◆ DoInstallFontFile()

HRESULT DoInstallFontFile ( _Out_ CStringW strMsg,
_In_ PCWSTR  pszFontPath,
_In_ PCWSTR  pszFontsDir,
_In_ HKEY  hkeyFonts 
)

Definition at line 150 of file fontext.cpp.

155{
156 WCHAR szDestFile[MAX_PATH];
157
158 // Add this font to the font list, so we can query the name
159 if (!AddFontResourceW(pszFontPath))
160 {
161 ERR("AddFontResourceW('%S') failed\n", pszFontPath);
162 return E_FAIL;
163 }
164
165 CStringW strFontName;
166 HRESULT hr = DoGetFontTitle(pszFontPath, strFontName);
167
168 // We got the name, remove it again
169 RemoveFontResourceW(pszFontPath);
170
171 if (!SUCCEEDED(hr))
172 {
173 ERR("DoGetFontTitle failed (err=0x%x)!\n", hr);
174 return hr;
175 }
176
177 StringCchCopyW(szDestFile, sizeof(szDestFile), pszFontsDir);
178
179 LPCWSTR pszFileTitle = PathFindFileName(pszFontPath);
180 PathAppendW(szDestFile, pszFileTitle);
181 if (!CopyFileW(pszFontPath, szDestFile, FALSE))
182 {
183 ERR("CopyFileW('%S', '%S') failed\n", pszFontPath, szDestFile);
184 return E_FAIL;
185 }
186
187 DWORD cbData = (wcslen(pszFileTitle) + 1) * sizeof(WCHAR);
188 LONG nError = RegSetValueExW(hkeyFonts, strFontName, 0, REG_SZ,
189 (const BYTE *)pszFileTitle, cbData);
190 if (nError)
191 {
192 ERR("RegSetValueExW failed with %ld\n", nError);
193 DeleteFileW(szDestFile);
194 return E_FAIL;
195 }
196
197 return AddFontResourceW(szDestFile) ? S_OK : E_FAIL;
198}
#define FALSE
Definition: types.h:117
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT DoGetFontTitle(_In_ LPCWSTR pszFontPath, _Out_ CStringW &strFontName)
Definition: fontext.cpp:201
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define REG_SZ
Definition: layer.c:22
#define PathAppendW
Definition: pathcch.h:309
long LONG
Definition: pedump.c:60
#define PathFindFileName
Definition: shlwapi.h:946
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
int WINAPI AddFontResourceW(_In_ LPCWSTR pszFilename)
Definition: font.c:2167
BOOL WINAPI RemoveFontResourceW(_In_ LPCWSTR)
Definition: font.c:2175
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by InstallFontFiles().

◆ InstallFontFiles()

HRESULT InstallFontFiles ( _Out_ CStringW strMessage,
_In_ PCUIDLIST_ABSOLUTE  pidlParent,
_In_ UINT  cidl,
_In_ PCUITEMID_CHILD_ARRAY  apidl 
)

Definition at line 104 of file fontext.cpp.

109{
110 CAtlArray<CStringW> FontPaths;
111 for (UINT n = 0; n < cidl; ++n)
112 {
114 pidl.Attach(ILCombine(pidlParent, apidl[n]));
115 if (!pidl)
116 {
117 ERR("Out of memory\n");
118 return E_OUTOFMEMORY;
119 }
120
124 {
125 ERR("Not font file: %s\n", wine_dbgstr_w(szPath));
126 return E_FAIL;
127 }
128
129 FontPaths.Add(szPath);
130 }
131
132 CRegKey keyFonts;
133 if (keyFonts.Open(FONT_HIVE, FONT_KEY, KEY_WRITE) != ERROR_SUCCESS)
134 {
135 ERR("CRegKey::Open failed\n");
136 return E_FAIL;
137 }
138
139 for (SIZE_T iItem = 0; iItem < FontPaths.GetCount(); ++iItem)
140 {
141 HRESULT hr = DoInstallFontFile(strMsg, FontPaths[iItem], g_FontCache->FontPath(), keyFonts);
143 return hr;
144 }
145
146 return S_OK;
147}
size_t Add(INARGTYPE element)
Definition: atlcoll.h:295
size_t GetCount() const
Definition: atlcoll.h:373
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE) noexcept
Definition: atlbase.h:1173
const CStringW & FontPath() const
Definition: CFontCache.hpp:51
void Attach(T *lp)
Definition: atlalloc.h:162
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL IsFontDotExt(LPCWSTR pchDotExt)
Definition: precomp.h:44
#define FONT_HIVE
Definition: precomp.h:35
#define FONT_KEY
Definition: precomp.h:36
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1729
HRESULT DoInstallFontFile(_Out_ CStringW &strMsg, _In_ PCWSTR pszFontPath, _In_ PCWSTR pszFontsDir, _In_ HKEY hkeyFonts)
Definition: fontext.cpp:150
#define wine_dbgstr_w
Definition: kernel32.h:34
LPCWSTR szPath
Definition: env.c:37
#define KEY_WRITE
Definition: nt_native.h:1031
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:816
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1489
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by CFontExt::Drop().

◆ IsFontDotExt()

BOOL IsFontDotExt ( LPCWSTR  pchDotExt)
inline

Definition at line 44 of file precomp.h.

45{
46 static const LPCWSTR array[] =
47 {
48 L".ttf", L".ttc", L".otf", L".otc", L".fon", L".fnt", NULL
49 };
50 for (const LPCWSTR *pp = array; *pp; ++pp)
51 {
52 if (!_wcsicmp(*pp, pchDotExt))
53 return TRUE;
54 }
55 return FALSE;
56}
#define TRUE
Definition: types.h:120
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by InstallFontFiles().

Variable Documentation

◆ CLSID_CFontExt

const GUID CLSID_CFontExt
extern

Definition at line 13 of file fontext.cpp.

Referenced by CFontExt::GetClassID().

◆ g_ModuleRefCnt

LONG g_ModuleRefCnt
extern

Definition at line 13 of file ACPPage.cpp.