📄 olepicture.c
字号:
ULONG refCount = InterlockedDecrement(&This->ref);
TRACE("(%p)->(ref before=%d)\n", This, refCount + 1);
/*
* If the reference count goes down to 0, perform suicide.
*/
if (!refCount) OLEPictureImpl_Destroy(This);
return refCount;
}
/************************************************************************
* OLEPictureImpl_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static HRESULT WINAPI OLEPictureImpl_QueryInterface(
IPicture* iface,
REFIID riid,
void** ppvObject)
{
OLEPictureImpl *This = (OLEPictureImpl *)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 (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPicture, riid))
*ppvObject = (IPicture*)This;
else if (IsEqualIID(&IID_IDispatch, riid))
*ppvObject = (IDispatch*)&(This->lpvtblIDispatch);
else if (IsEqualIID(&IID_IPictureDisp, riid))
*ppvObject = (IDispatch*)&(This->lpvtblIDispatch);
else if (IsEqualIID(&IID_IPersist, riid) || IsEqualIID(&IID_IPersistStream, riid))
*ppvObject = (IPersistStream*)&(This->lpvtblIPersistStream);
else if (IsEqualIID(&IID_IConnectionPointContainer, riid))
*ppvObject = (IConnectionPointContainer*)&(This->lpvtblIConnectionPointContainer);
/*
* Check that we obtained an interface.
*/
if ((*ppvObject)==0)
{
FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
return E_NOINTERFACE;
}
/*
* Query Interface always increases the reference count by one when it is
* successful
*/
OLEPictureImpl_AddRef((IPicture*)This);
return S_OK;
}
/***********************************************************************
* OLEPicture_SendNotify (internal)
*
* Sends notification messages of changed properties to any interested
* connections.
*/
static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
{
IEnumConnections *pEnum;
CONNECTDATA CD;
if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
return;
while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
IPropertyNotifySink *sink;
IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
IPropertyNotifySink_OnChanged(sink, dispID);
IPropertyNotifySink_Release(sink);
IUnknown_Release(CD.pUnk);
}
IEnumConnections_Release(pEnum);
return;
}
/************************************************************************
* OLEPictureImpl_get_Handle
*/
static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
OLE_HANDLE *phandle)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p)\n", This, phandle);
switch(This->desc.picType) {
case PICTYPE_NONE:
case PICTYPE_UNINITIALIZED:
*phandle = 0;
break;
case PICTYPE_BITMAP:
*phandle = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
break;
case PICTYPE_METAFILE:
*phandle = (OLE_HANDLE)This->desc.u.wmf.hmeta;
break;
case PICTYPE_ICON:
*phandle = (OLE_HANDLE)This->desc.u.icon.hicon;
break;
case PICTYPE_ENHMETAFILE:
*phandle = (OLE_HANDLE)This->desc.u.emf.hemf;
break;
default:
FIXME("Unimplemented type %d\n", This->desc.picType);
return E_NOTIMPL;
}
TRACE("returning handle %08x\n", *phandle);
return S_OK;
}
/************************************************************************
* OLEPictureImpl_get_hPal
*/
static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
OLE_HANDLE *phandle)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
HRESULT hres;
TRACE("(%p)->(%p)\n", This, phandle);
if (!phandle)
return E_POINTER;
switch (This->desc.picType) {
case PICTYPE_UNINITIALIZED:
case PICTYPE_NONE:
*phandle = 0;
hres = S_FALSE;
break;
case PICTYPE_BITMAP:
*phandle = (OLE_HANDLE)This->desc.u.bmp.hpal;
hres = S_OK;
break;
case PICTYPE_ICON:
case PICTYPE_METAFILE:
case PICTYPE_ENHMETAFILE:
default:
FIXME("unimplemented for type %d. Returning 0 palette.\n",
This->desc.picType);
*phandle = 0;
hres = S_OK;
}
TRACE("returning 0x%08x, palette handle %08x\n", hres, *phandle);
return hres;
}
/************************************************************************
* OLEPictureImpl_get_Type
*/
static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
short *ptype)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
*ptype = This->desc.picType;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_get_Width
*/
static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
OLE_XSIZE_HIMETRIC *pwidth)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p): width is %d\n", This, pwidth, This->himetricWidth);
*pwidth = This->himetricWidth;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_get_Height
*/
static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
OLE_YSIZE_HIMETRIC *pheight)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p): height is %d\n", This, pheight, This->himetricHeight);
*pheight = This->himetricHeight;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_Render
*/
static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
LONG x, LONG y, LONG cx, LONG cy,
OLE_XPOS_HIMETRIC xSrc,
OLE_YPOS_HIMETRIC ySrc,
OLE_XSIZE_HIMETRIC cxSrc,
OLE_YSIZE_HIMETRIC cySrc,
LPCRECT prcWBounds)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p, (%d,%d), (%d,%d) <- (%d,%d), (%d,%d), %p)\n",
This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
if(prcWBounds)
TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
prcWBounds->right, prcWBounds->bottom);
/*
* While the documentation suggests this to be here (or after rendering?)
* it does cause an endless recursion in my sample app. -MM 20010804
OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
*/
switch(This->desc.picType) {
case PICTYPE_BITMAP:
{
HBITMAP hbmpOld;
HDC hdcBmp;
/* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
NB y-axis gets flipped */
hdcBmp = CreateCompatibleDC(0);
SetMapMode(hdcBmp, MM_ANISOTROPIC);
SetWindowOrgEx(hdcBmp, 0, 0, NULL);
SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
if (This->hbmMask) {
HDC hdcMask = CreateCompatibleDC(0);
HBITMAP hOldbm = SelectObject(hdcMask, This->hbmMask);
hbmpOld = SelectObject(hdcBmp, This->hbmXor);
SetMapMode(hdcMask, MM_ANISOTROPIC);
SetWindowOrgEx(hdcMask, 0, 0, NULL);
SetWindowExtEx(hdcMask, This->himetricWidth, This->himetricHeight, NULL);
SetViewportOrgEx(hdcMask, 0, This->origHeight, NULL);
SetViewportExtEx(hdcMask, This->origWidth, -This->origHeight, NULL);
SetBkColor(hdc, RGB(255, 255, 255));
SetTextColor(hdc, RGB(0, 0, 0));
StretchBlt(hdc, x, y, cx, cy, hdcMask, xSrc, ySrc, cxSrc, cySrc, SRCAND);
StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCPAINT);
SelectObject(hdcMask, hOldbm);
DeleteDC(hdcMask);
} else {
hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
}
SelectObject(hdcBmp, hbmpOld);
DeleteDC(hdcBmp);
}
break;
case PICTYPE_ICON:
FIXME("Not quite correct implementation of rendering icons...\n");
DrawIcon(hdc,x,y,This->desc.u.icon.hicon);
break;
case PICTYPE_METAFILE:
PlayMetaFile(hdc, This->desc.u.wmf.hmeta);
break;
case PICTYPE_ENHMETAFILE:
{
RECT rc = { x, y, cx, cy };
PlayEnhMetaFile(hdc, This->desc.u.emf.hemf, &rc);
break;
}
default:
FIXME("type %d not implemented\n", This->desc.picType);
return E_NOTIMPL;
}
return S_OK;
}
/************************************************************************
* OLEPictureImpl_set_hPal
*/
static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
OLE_HANDLE hpal)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
FIXME("(%p)->(%08x): stub\n", This, hpal);
OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
return E_NOTIMPL;
}
/************************************************************************
* OLEPictureImpl_get_CurDC
*/
static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
HDC *phdc)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p), returning %p\n", This, This->hDCCur);
if (phdc) *phdc = This->hDCCur;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_SelectPicture
*/
static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
HDC hdcIn,
HDC *phdcOut,
OLE_HANDLE *phbmpOut)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
if (This->desc.picType == PICTYPE_BITMAP) {
SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
if (phdcOut)
*phdcOut = This->hDCCur;
This->hDCCur = hdcIn;
if (phbmpOut)
*phbmpOut = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
return S_OK;
} else {
FIXME("Don't know how to select picture type %d\n",This->desc.picType);
return E_FAIL;
}
}
/************************************************************************
* OLEPictureImpl_get_KeepOriginalFormat
*/
static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
BOOL *pfKeep)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p)\n", This, pfKeep);
if (!pfKeep)
return E_POINTER;
*pfKeep = This->keepOrigFormat;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_put_KeepOriginalFormat
*/
static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
BOOL keep)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%d)\n", This, keep);
This->keepOrigFormat = keep;
/* FIXME: what DISPID notification here? */
return S_OK;
}
/************************************************************************
* OLEPictureImpl_PictureChanged
*/
static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->()\n", This);
OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
This->bIsDirty = TRUE;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_SaveAsFile
*/
static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
IStream *pstream,
BOOL SaveMemCopy,
LONG *pcbSize)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This, pstream, SaveMemCopy, pcbSize);
return IStream_Write(pstream,This->data,This->datalen,(ULONG*)pcbSize);
}
/************************************************************************
* OLEPictureImpl_get_Attributes
*/
static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
DWORD *pdwAttr)
{
OLEPictureImpl *This = (OLEPictureImpl *)iface;
TRACE("(%p)->(%p).\n", This, pdwAttr);
*pdwAttr = 0;
switch (This->desc.picType) {
case PICTYPE_BITMAP: if (This->hbmMask) *pdwAttr = PICTURE_TRANSPARENT; break; /* not 'truly' scalable, see MSDN. */
case PICTYPE_ICON: *pdwAttr = PICTURE_TRANSPARENT;break;
case PICTYPE_ENHMETAFILE: /* fall through */
case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -