summaryrefslogtreecommitdiff
path: root/plugins/TabSRMM/src/ImageDataObject.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2016-12-07 17:57:30 +0300
committerGeorge Hazan <ghazan@miranda.im>2016-12-07 17:57:30 +0300
commitd6902f812511786ded73a5d87e3e788e47853365 (patch)
treedfd58de94078c9a163144f2e827d7bdb440fc2c5 /plugins/TabSRMM/src/ImageDataObject.cpp
parentfb2614dce27af59cc5385934eb1d893c47ee0cdd (diff)
TabSRMM:
- fixes #643 (Tabsrmm "insert image" button regression); - massive code cleaning
Diffstat (limited to 'plugins/TabSRMM/src/ImageDataObject.cpp')
-rw-r--r--plugins/TabSRMM/src/ImageDataObject.cpp140
1 files changed, 21 insertions, 119 deletions
diff --git a/plugins/TabSRMM/src/ImageDataObject.cpp b/plugins/TabSRMM/src/ImageDataObject.cpp
index c7de9efd61..cefd6547cc 100644
--- a/plugins/TabSRMM/src/ImageDataObject.cpp
+++ b/plugins/TabSRMM/src/ImageDataObject.cpp
@@ -31,126 +31,48 @@
#include "stdafx.h"
-extern void ReleaseRichEditOle(IRichEditOle *ole)
-{
- ole->Release();
-}
-
-extern void ImageDataInsertBitmap(IRichEditOle *ole, HBITMAP hBm)
-{
- CImageDataObject::InsertBitmap(ole, hBm);
-}
-
-int CacheIconToBMP(TLogIcon *theIcon, HICON hIcon, COLORREF backgroundColor, int sizeX, int sizeY)
-{
- int IconSizeX = sizeX;
- int IconSizeY = sizeY;
-
- if ((IconSizeX == 0) || (IconSizeY == 0)) {
- Utils::getIconSize(hIcon, IconSizeX, IconSizeY);
- if (sizeX != 0)
- IconSizeX = sizeX;
- if (sizeY != 0)
- IconSizeY = sizeY;
- }
- RECT rc;
- BITMAPINFOHEADER bih = { 0 };
- int widthBytes;
- theIcon->hBkgBrush = CreateSolidBrush(backgroundColor);
- bih.biSize = sizeof(bih);
- bih.biBitCount = 24;
- bih.biPlanes = 1;
- bih.biCompression = BI_RGB;
- bih.biHeight = IconSizeY;
- bih.biWidth = IconSizeX;
- widthBytes = ((bih.biWidth * bih.biBitCount + 31) >> 5) * 4;
- rc.top = rc.left = 0;
- rc.right = bih.biWidth;
- rc.bottom = bih.biHeight;
- theIcon->hdc = GetDC(0);
- theIcon->hBmp = CreateCompatibleBitmap(theIcon->hdc, bih.biWidth, bih.biHeight);
- theIcon->hdcMem = CreateCompatibleDC(theIcon->hdc);
- theIcon->hoBmp = (HBITMAP)SelectObject(theIcon->hdcMem, theIcon->hBmp);
- FillRect(theIcon->hdcMem, &rc, theIcon->hBkgBrush);
- DrawIconEx(theIcon->hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
- SelectObject(theIcon->hdcMem, theIcon->hoBmp);
- return TRUE;
-}
-
-void DeleteCachedIcon(TLogIcon *theIcon)
-{
- DeleteDC(theIcon->hdcMem);
- DeleteObject(theIcon->hBmp);
- ReleaseDC(NULL, theIcon->hdc);
- DeleteObject(theIcon->hBkgBrush);
-}
-
// returns true on success, false on failure
bool CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap)
{
- SCODE sc;
- BITMAP bminfo;
-
// Get the image data object
- //
CImageDataObject *pods = new CImageDataObject;
- LPDATAOBJECT lpDataObject;
- pods->QueryInterface(IID_IDataObject, (void **)&lpDataObject);
+ CComPtr<IDataObject> lpDataObject;
+ pods->QueryInterface(IID_IDataObject, (void**)&lpDataObject);
+ BITMAP bminfo;
GetObject(hBitmap, sizeof(bminfo), &bminfo);
pods->SetBitmap(hBitmap);
// Get the RichEdit container site
- //
- IOleClientSite *pOleClientSite;
+ CComPtr<IOleClientSite> pOleClientSite;
pRichEditOle->GetClientSite(&pOleClientSite);
- // Initialize a Storage Object
- //
- IStorage *pStorage;
-
- LPLOCKBYTES lpLockBytes = NULL;
- sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
- if (sc != S_OK) {
- pOleClientSite->Release();
+ CComPtr<ILockBytes> lpLockBytes;
+ if (FAILED(::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes)))
return false;
- }
- sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
- STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage);
- if (sc != S_OK) {
- lpLockBytes = NULL;
- pOleClientSite->Release();
+
+ // Initialize a Storage Object
+ CComPtr<IStorage> pStorage;
+ if (FAILED(::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage)))
return false;
- }
+
// The final ole object which will be inserted in the richedit control
- //
- IOleObject *pOleObject;
- pOleObject = pods->GetOleObject(pOleClientSite, pStorage);
- if (pOleObject == NULL) {
- pStorage->Release();
- pOleClientSite->Release();
+ CComPtr<IOleObject> pOleObject = pods->GetOleObject(pOleClientSite, pStorage);
+ if (pOleObject == NULL)
return false;
- }
// all items are "contained" -- this makes our reference to this object
// weak -- which is needed for links to embedding silent update.
OleSetContainedObject(pOleObject, TRUE);
// Now Add the object to the RichEdit
- //
- REOBJECT reobject;
- memset(&reobject, 0, sizeof(REOBJECT));
- reobject.cbStruct = sizeof(REOBJECT);
-
CLSID clsid;
- sc = pOleObject->GetUserClassID(&clsid);
- if (sc != S_OK) {
- pOleObject->Release();
- pStorage->Release();
- pOleClientSite->Release();
+ if (FAILED(pOleObject->GetUserClassID(&clsid)))
return false;
- }
+ // Insert the bitmap at the current location in the richedit control
+ REOBJECT reobject = {};
+ reobject.cbStruct = sizeof(REOBJECT);
reobject.clsid = clsid;
reobject.cp = REO_CP_SELECTION;
reobject.dvaspect = DVASPECT_CONTENT;
@@ -158,25 +80,9 @@ bool CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap)
reobject.polesite = pOleClientSite;
reobject.pstg = pStorage;
reobject.dwFlags = bminfo.bmHeight <= 12 ? 0 : REO_BELOWBASELINE;
-
- // Insert the bitmap at the current location in the richedit control
- //
- sc = pRichEditOle->InsertObject(&reobject);
-
- // Release all unnecessary interfaces
- //
- pOleObject->Release();
- pOleClientSite->Release();
- lpLockBytes->Release();
- pStorage->Release();
- lpDataObject->Release();
- if (sc != S_OK)
- return false;
- else
- return true;
+ return pRichEditOle->InsertObject(&reobject) == S_OK;
}
-
void CImageDataObject::SetBitmap(HBITMAP hBitmap)
{
STGMEDIUM stgm;
@@ -194,14 +100,10 @@ void CImageDataObject::SetBitmap(HBITMAP hBitmap)
this->SetData(&fm, &stgm, TRUE);
}
-
-IOleObject *CImageDataObject::GetOleObject(IOleClientSite *pOleClientSite, IStorage *pStorage)
+IOleObject* CImageDataObject::GetOleObject(IOleClientSite *pOleClientSite, IStorage *pStorage)
{
- SCODE sc;
IOleObject *pOleObject;
- sc = ::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT,
- &m_format, pOleClientSite, pStorage, (void **)& pOleObject);
- if (sc != S_OK)
- pOleObject = NULL;
+ if (FAILED(::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT, &m_format, pOleClientSite, pStorage, (void **)&pOleObject)))
+ return NULL;
return pOleObject;
}