#include "StdAfx.h"
#include "RichEditUtil.h"
#include "shared/image_ole_i.h"
//#include "richedit_olecallback.h"
#pragma warning(disable: 4996)
#define EMOJI_SIZE 24
#define MAX_CUSTOM_ITEM_W 240
#define MAX_CUSTOM_ITEM_H 240
#define MAX_CUSTOM_FILE_W 200
#ifdef DEBUG
#define IMAGE_OLE_NAME L"image_ole_d.dll"
#else
#define IMAGE_OLE_NAME L"image_ole.dll"
#endif
static HMODULE image_ole_module_ = NULL;
void FreeImageoleModule()
{
if (image_ole_module_)
{
FreeLibrary(image_ole_module_);
image_ole_module_ = NULL;
}
}
typedef HRESULT(WINAPI* DLLGETCLASSOBJECTFUNC) (REFCLSID rclsid, REFIID riid, LPVOID* ppv);
bool CreateImageObject(void **ppv)
{
*ppv = NULL;
if (image_ole_module_ == NULL)
{
std::wstring dll_path = QPath::GetAppPath();
dll_path.append(IMAGE_OLE_NAME);
image_ole_module_ = LoadLibrary(dll_path.c_str());
}
if (image_ole_module_ == NULL)
{
return false;
}
DLLGETCLASSOBJECTFUNC pFunc = (DLLGETCLASSOBJECTFUNC)GetProcAddress(image_ole_module_, "DllGetClassObject");
if (pFunc == NULL)
{
FreeImageoleModule();
return false;
}
CComPtr<IClassFactory> pFactory;
HRESULT hr = (*pFunc)(CLSID_ImageOle/*你的组件CLSID*/, IID_IClassFactory, (void**)&pFactory);
if (hr == S_OK)
hr = pFactory->CreateInstance(0, IID_IImageOle, ppv);
if (hr != S_OK || *ppv == NULL)
{
FreeImageoleModule();
return false;
}
return true;
}
IRichEditOle* Re_GetOleInterface(ITextServices *text_service)
{
IRichEditOle *pRichEditOle = NULL;
text_service->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle, NULL);
return pRichEditOle;
}
bool Re_InsertCustomItem(ITextServices *text_service, InsertCustomItemErrorCallback callback, bool total_count_limit, const std::wstring& file, const std::wstring& face_tag, int ole_type
, int face_id, bool scale, int scale_width, int scale_height, LONG cp, const std::wstring& voice_file)
{
if (total_count_limit && ole_type >= RE_OLE_TYPE_CUSTOM && Re_GetCustomImageOleCount(text_service) >= MAX_CUSTOM_ITEM_NUM)
{
if (callback)
{
Post2UI(callback);
}
return false;
}
if (text_service == NULL)
return false;
//m_RichEdit为您的RichEdit对象
IRichEditOle* lpRichEditOle = Re_GetOleInterface(text_service);
if (lpRichEditOle == NULL)
return false;
//OLE对象
IOleObject* lpOleObject = NULL;
IOleClientSite* lpOleClientSite = NULL;
CComPtr<IImageOle> image_ole;
CLSID clsid;
REOBJECT reobject;
HRESULT hr = S_FALSE;
do
{
{
if (!CreateImageObject((LPVOID*)&image_ole))
break;
}
//获得数据对象接口
hr = image_ole->QueryInterface(IID_IOleObject, (void**)&lpOleObject);
if (hr != S_OK)
break;
hr = lpOleObject->GetUserClassID(&clsid);
if (hr != S_OK)
break;
hr = lpRichEditOle->GetClientSite(&lpOleClientSite);
if (hr != S_OK)
break;
//初始化一个对象
ZeroMemory(&reobject, sizeof(REOBJECT));
reobject.cbStruct = sizeof(REOBJECT);
reobject.clsid = clsid;
reobject.cp = cp;
reobject.dvaspect = DVASPECT_CONTENT;
reobject.dwFlags = REO_BELOWBASELINE;
reobject.poleobj = lpOleObject;
reobject.polesite = lpOleClientSite;
reobject.pstg = NULL;// lpStorage;
lpOleObject->SetClientSite(lpOleClientSite);
std::wstring image_path = file;
image_ole->SetFaceTag((BSTR)(face_tag.c_str()));
image_ole->SetFaceIndex(ole_type);
image_ole->SetFaceId(face_id);
if (ole_type == RE_OLE_TYPE_FILE)
{
// OSVERSIONINFO os = { sizeof(OSVERSIONINFO) };
// ::GetVersionEx(&os);
// std::wstring fontName = os.dwMajorVersion >= 6 ?
// ui::MutiLanSupport::GetInstance()->GetStringViaID(L"STRING_GLOBALMANAGER_FONT_MSYH")
// :
// ui::MutiLanSupport::GetInstance()->GetStringViaID(L"STRING_GLOBALMANAGER_FONT_DEFXP");
// image_ole->SetFont((BSTR)(fontName.c_str()), 20, RGB(0x1a, 0x30, 0x47));
if (image_path.size() == 0)
{
image_path = GetIconByFile(face_tag);
}
image_ole->SetBgColor(RGB(255, 255, 255));
}
else if (ole_type == RE_OLE_TYPE_IMAGELOADING)
{
if (image_path.size() == 0)
{
image_path = QPath::GetAppPath();
image_path.append(L"res\\icons\\loading.gif");
}
}
image_ole->SetScaleSize(scale, scale_width, scale_height);
image_ole->LoadFromFile((BSTR)(image_path.c_str()));
//std::wstring guid = nbase::UTF8ToUTF16(QString::GetGUID());
string sGuid;
CTool::CreateGUID(sGuid);
std::wstring guid = nbase::UTF8ToUTF16(sGuid);
image_ole->SetGUID((BSTR)guid.c_str());
//语音文件的文件名voice_file
if (voice_file.size() != 0)
{
image_ole->SetGUID((BSTR)(voice_file.c_str()));
}
OleSetContainedObject(lpOleObject, TRUE);
hr = lpRichEditOle->InsertObject(&reobject);
} while (0);
if (lpOleObject != NULL)
lpOleObject->Release();
if (lpOleClientSite != NULL)
lpOleClientSite->Release();
lpRichEditOle->Release();
return hr == S_OK;
}
bool Re_InsertDescriptionItem(ITextServices *text_service, InsertCustomItemErrorCallback callback, bool total_count_limit, const std::wstring& description
, const std::wstring& face_tag, int ole_type, COLORREF clrBg/* = RGB(255, 255, 255)*/, COLORREF clrfont/* = RGB(35, 142, 250)*/, int fontSize/* = 20*/, LONG cp/* = REO_CP_SELECTION*/)
{
if (total_count_limit && ole_type >= RE_OLE_TYPE_CUSTOM && Re_GetCustomImageOleCount(text_service) >= MAX_CUSTOM_ITEM_NUM)
{
if (callback)
{
Post2UI(callback);
}
return false;
}
if (text_service == NULL)
return false;
//m_RichEdit为您的RichEdit对象
IRichEditOle* lpRichEditOle = Re_GetOleInterface(text_service);
if (lpRichEditOle == NULL)
return false;
//OLE对象
IOleObject* lpOleObject = NULL;
IOleClientSite* lpOleClientSite = NULL;
CComPtr<IImageOle> image_ole;
CLSID clsid;
REOBJECT reobject;
HRESULT hr = S_FALSE;
do
{
{
if (!CreateImageObject((LPVOID*)&image_ole))
break;
}
//获得数据对象接口
hr = image_ole->QueryInterface(IID_IOleObject, (void**)&lpOleObject);
if (hr != S_OK)
break;
hr = lpOleObject->GetUserClassID(&clsid);
if (hr != S_OK)
break;
hr = lpRichEditOle->GetClientSite(&lpOleClientSite);
if (hr != S_OK)
break;
//初始化一个对象
ZeroMemory(&reobject, sizeof(REOBJECT));
reobject.cbStruct = sizeof(REOBJECT);
reobject.clsid = clsid;
reobject.cp = cp;
reobject.dvaspect = DVASPECT_CONTENT;
reobject.dwFlags = REO_BELOWBASELINE;
reobject.poleobj = lpOleObject;
reobject.polesite = lpOleClientSite;
reobject.pstg = NULL;// lpStorage;
lpOleObject->SetClientSite(lpOleClientSite);
// std::wstring image_path = file;
image_ole->SetFaceTag((BSTR)(face_tag.c_str()));
image_ole->SetFaceIndex(ole_type);
// image_ole->SetFaceId(face_id);
// OSVERSIONINFO os = { sizeof(OSVERSIONINFO) };
// ::GetVersionEx(&os);
// std::wstring fontName = os.dwMajorVersion >= 6 ?
// ui::MutiLanSupport::GetInstance()->GetStringViaID(L"STRING_GLOBALMANAGER_FONT_MSYH")
// :
// ui::MutiLanSupport::GetInstance()->GetStringViaID(L"STRING_GLOBALMANAGER_FONT_DEFXP");
//std::wstring fontName = _T("");
//image_ole->SetFont((BSTR)(fontName.c_str()), fontSize, clrfont);
image_ole->SetBgColor(clrBg);
// image_ole->SetScaleSize(scale, scale_width, scale_height);
image_ole->LoadFromDescription((BSTR)(description.c_str()));
string sGuid;
CTool::CreateGUID(sGuid);
std::wstring guid = nbase::UTF8ToUTF16(sGuid);
image_ole->SetGUID((BSTR)guid.c_str());
OleSetContainedObject(lpOleObject, TRUE);
hr = lpRichEditOle->InsertObject(&reobject);
} while (0);
if (lpOleObject != NULL)
lpOleObject->Release();
if (lpOleClientSite != NULL)
lpOleClientSite->Release();
lpRichEditOle->Release();
return hr == S_OK;
}
bool Re_InsertFace(ITextServices *text_service, const std::wstring& file, const std::wstring& face_tag)
{
int emoji_size = EMOJI_SIZE;
ui::DpiManager::GetI
richedit.rar
需积分: 29 102 浏览量
2020-06-30
17:58:38
上传
评论
收藏 499KB RAR 举报
yuer_xiao
- 粉丝: 35
- 资源: 6
最新资源
- 软件工程项目验收系列文档.doc
- content_1713513663833.xmind
- 数据流图(Data Flow Diagram,简称DFD).md
- 基于Mybatis-Plus的Maven代码生成插件设计源码
- 67e1bc92-b0ee-45c1-b46f-9d519bbd6925.ofd
- npcsvpwm.v
- Java项目:基于Springboot+vue实现的校园志愿者管理系统(源码+数据库+环境配置和运行指导视频+系统讲解视频)
- 驱动开发,驱动加载工具,支持安装、启动、停止、卸载、关闭功能
- UTS 32146 Data Visualisation and Visual Analytics A1
- 西门子1200PLC 六部十层电梯程序案例,WINCC RT Advanced界面,博图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈