📄 olefont.c
字号:
VARIANTARG vararg;
VariantInit(&vararg);
V_VT(&vararg) = VT_BSTR;
V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
dispparams.cArgs = 1;
dispparams.cNamedArgs = 0;
dispparams.rgdispidNamedArgs = NULL;
dispparams.rgvarg = &vararg;
while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
IFontEventsDisp *disp;
IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
NULL, NULL);
IDispatch_Release(disp);
IUnknown_Release(CD.pUnk);
}
VariantClear(&vararg);
IEnumConnections_Release(pEnum);
}
}
/************************************************************************
* OLEFontImpl_Construct
*
* This method will construct a new instance of the OLEFontImpl
* class.
*
* The caller of this method must release the object when it's
* done with it.
*/
static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
{
OLEFontImpl* newObject = 0;
/*
* Allocate space for the object.
*/
newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
if (newObject==0)
return newObject;
/*
* Initialize the virtual function table.
*/
newObject->lpVtbl = &OLEFontImpl_VTable;
newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
/*
* Start with one reference count. The caller of this function
* must release the interface pointer when it is done.
*/
newObject->ref = 1;
/*
* Copy the description of the font in the object.
*/
assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
newObject->description.cbSizeofstruct = sizeof(FONTDESC);
newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
0,
(lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
newObject->description.cySize = fontDesc->cySize;
newObject->description.sWeight = fontDesc->sWeight;
newObject->description.sCharset = fontDesc->sCharset;
newObject->description.fItalic = fontDesc->fItalic;
newObject->description.fUnderline = fontDesc->fUnderline;
newObject->description.fStrikethrough = fontDesc->fStrikethrough;
/*
* Initializing all the other members.
*/
newObject->gdiFont = 0;
newObject->fontLock = 0;
newObject->cyLogical = 72L;
newObject->cyHimetric = 2540L;
newObject->pPropertyNotifyCP = NULL;
newObject->pFontEventsCP = NULL;
CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
{
OLEFontImpl_Destroy(newObject);
return NULL;
}
TRACE("returning %p\n", newObject);
return newObject;
}
/************************************************************************
* OLEFontImpl_Destroy
*
* This method is called by the Release method when the reference
* count goes down to 0. It will free all resources used by
* this object.
*/
static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
{
TRACE("(%p)\n", fontDesc);
HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
if (fontDesc->gdiFont!=0)
DeleteObject(fontDesc->gdiFont);
if (fontDesc->pPropertyNotifyCP)
IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
if (fontDesc->pFontEventsCP)
IConnectionPoint_Release(fontDesc->pFontEventsCP);
HeapFree(GetProcessHeap(), 0, fontDesc);
}
/************************************************************************
* OLEFontImpl_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
HRESULT WINAPI OLEFontImpl_QueryInterface(
IFont* iface,
REFIID riid,
void** ppvObject)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
/*
* Perform a sanity check on the parameters.
*/
if ( (this==0) || (ppvObject==0) )
return E_INVALIDARG;
/*
* Initialize the return parameter.
*/
*ppvObject = 0;
/*
* Compare the riid with the interface IDs implemented by this object.
*/
if (IsEqualGUID(&IID_IUnknown, riid))
*ppvObject = (IFont*)this;
if (IsEqualGUID(&IID_IFont, riid))
*ppvObject = (IFont*)this;
if (IsEqualGUID(&IID_IDispatch, riid))
*ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
if (IsEqualGUID(&IID_IFontDisp, riid))
*ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
if (IsEqualGUID(&IID_IPersistStream, riid))
*ppvObject = (IPersistStream*)&(this->lpvtblIPersistStream);
if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
*ppvObject = (IConnectionPointContainer*)&(this->lpvtblIConnectionPointContainer);
if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
*ppvObject = (IPersistPropertyBag*)&(this->lpvtblIPersistPropertyBag);
if (IsEqualGUID(&IID_IPersistStreamInit, riid))
*ppvObject = (IPersistStreamInit*)&(this->lpvtblIPersistStreamInit);
/*
* Check that we obtained an interface.
*/
if ((*ppvObject)==0)
{
FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
return E_NOINTERFACE;
}
OLEFontImpl_AddRef((IFont*)this);
return S_OK;
}
/************************************************************************
* OLEFontImpl_AddRef (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
ULONG WINAPI OLEFontImpl_AddRef(
IFont* iface)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(ref=%ld)\n", this, this->ref);
return InterlockedIncrement(&this->ref);
}
/************************************************************************
* OLEFontImpl_Release (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
ULONG WINAPI OLEFontImpl_Release(
IFont* iface)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
ULONG ret;
TRACE("(%p)->(ref=%ld)\n", this, this->ref);
/*
* Decrease the reference count on this object.
*/
ret = InterlockedDecrement(&this->ref);
/*
* If the reference count goes down to 0, perform suicide.
*/
if (ret==0) OLEFontImpl_Destroy(this);
return ret;
}
/************************************************************************
* OLEFontImpl_get_Name (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Name(
IFont* iface,
BSTR* pname)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pname);
/*
* Sanity check.
*/
if (pname==0)
return E_POINTER;
if (this->description.lpstrName!=0)
*pname = SysAllocString(this->description.lpstrName);
else
*pname = 0;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Name (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Name(
IFont* iface,
BSTR name)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, name);
if (this->description.lpstrName==0)
{
this->description.lpstrName = HeapAlloc(GetProcessHeap(),
0,
(lstrlenW(name)+1) * sizeof(WCHAR));
}
else
{
this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
0,
this->description.lpstrName,
(lstrlenW(name)+1) * sizeof(WCHAR));
}
if (this->description.lpstrName==0)
return E_OUTOFMEMORY;
strcpyW(this->description.lpstrName, name);
TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
OLEFont_SendNotify(this, DISPID_FONT_NAME);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Size (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Size(
IFont* iface,
CY* psize)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, psize);
/*
* Sanity check
*/
if (psize==0)
return E_POINTER;
psize->s.Hi = 0;
psize->s.Lo = this->description.cySize.s.Lo;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Size (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Size(
IFont* iface,
CY size)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%ld)\n", this, size.s.Lo);
this->description.cySize.s.Hi = 0;
this->description.cySize.s.Lo = size.s.Lo;
OLEFont_SendNotify(this, DISPID_FONT_SIZE);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Bold (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Bold(
IFont* iface,
BOOL* pbold)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pbold);
/*
* Sanity check
*/
if (pbold==0)
return E_POINTER;
*pbold = this->description.sWeight > 550;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Bold (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Bold(
IFont* iface,
BOOL bold)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, bold);
this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
OLEFont_SendNotify(this, DISPID_FONT_BOLD);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Italic (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Italic(
IFont* iface,
BOOL* pitalic)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pitalic);
/*
* Sanity check
*/
if (pitalic==0)
return E_POINTER;
*pitalic = this->description.fItalic;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Italic (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Italic(
IFont* iface,
BOOL italic)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, italic);
this->description.fItalic = italic;
OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Underline (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Underline(
IFont* iface,
BOOL* punderline)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, punderline);
/*
* Sanity check
*/
if (punderline==0)
return E_POINTER;
*punderline = this->description.fUnderline;
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -