Ejemplo n.º 1
0
void UIIMEdit::_ImEditPaste()
{
	BOOL bHadPic = FALSE;
	if (::OpenClipboard(::GetDesktopWindow()))
	{
		if (IsClipboardFormatAvailable(CF_BITMAP))
		{
			HBITMAP hBitmap = (HBITMAP)::GetClipboardData(CF_BITMAP);
			BITMAP bitmap;
			GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bitmap);
			SIZE bitmapSize = { bitmap.bmWidth, bitmap.bmHeight };
			if (hBitmap)
			{
				_SaveFile(hBitmap, m_strImagePath);
				InsertImage(m_strImagePath.GetBuffer(), bitmapSize, FALSE);
				bHadPic = TRUE;
			}
		}
		else if (IsClipboardFormatAvailable(CF_HDROP))
		{
			HDROP hDrop = (HDROP)GetClipboardData(CF_HDROP);
			onDropFiles(hDrop);
		}
		CloseClipboard();
	}
}
Ejemplo n.º 2
0
//翻译字符
bool CRichEditMessage::TranslateInsertString(LPCTSTR pszString, COLORREF crColor)
{
	//翻译判断
	if (m_pExpressionManager==NULL) return false;

	//变量定义
	tagTranslateResult TranslateResult;
	ZeroMemory(&TranslateResult,sizeof(TranslateResult));

	//字符变量
	INT nTranslateIndex=0;
	INT nStringLength=lstrlen(pszString);

	while ((nStringLength-nTranslateIndex)>0)
	{
		//解释字符
		bool bSuccess=m_pExpressionManager->TranslateString(&pszString[nTranslateIndex],TranslateResult);

		//结果处理
		if (bSuccess==true)
		{
			//插入字符
			if (TranslateResult.nStartPos>0)
			{
				//变量定义
				TCHAR szString[LEN_USER_CHAT]=TEXT("");
				WORD wCopyCount=__min(TranslateResult.nStartPos,CountArray(szString));

				//构造字符
				szString[wCopyCount]=0;
				CopyMemory(szString,&pszString[nTranslateIndex],wCopyCount*sizeof(TCHAR));

				//插入字符
				InsertString(szString,crColor);
			}

			//构造路径
			TCHAR ImagePath[MAX_PATH]=TEXT("");
			TranslateResult.pExpressionItem->GetExpressionPath(ImagePath,CountArray(ImagePath));

			//插入表情
			InsertImage(ImagePath);

			//设置索引
			nTranslateIndex+=TranslateResult.nStartPos+TranslateResult.nDescribeLen;
		}
		else
		{
			//插入字符
			InsertString(&pszString[nTranslateIndex],crColor);
			break;
		}

	}

	return true;
}
Ejemplo n.º 3
0
//用户表情
bool CRichEditMessage::InsertExpression(LPCTSTR pszSendUser, LPCTSTR pszImagePath, bool bMyselfString)
{
	//获取时间
	SYSTEMTIME SystemTime;
	GetLocalTime(&SystemTime);

	//保存选择
	CHARRANGE CharRange;
	GetSel(CharRange);

	//插入前叠
	TCHAR szTimeString[64]=TEXT("");
	_sntprintf(szTimeString,CountArray(szTimeString),TEXT("\r\n%s [ %02d:%02d:%02d ]\r\n"),pszSendUser,SystemTime.wHour,SystemTime.wMinute,SystemTime.wSecond);
	InsertString(szTimeString,(bMyselfString==true)?COLOR_MYSELF:COLOR_USER);

	//格式数据
	PARAFORMAT2 ParaFormat;
	ZeroMemory(&ParaFormat,sizeof(ParaFormat));
	ParaFormat.cbSize=sizeof(ParaFormat);
	ParaFormat.dwMask=PFM_OFFSETINDENT;
	ParaFormat.dxStartIndent=200L;

	//设置缩进
	SetSel(-1L,-1L);
	SetParaFormat(ParaFormat);

	//插入表情
	InsertImage(pszImagePath);
	InsertString(TEXT("\r\n"),RGB(255,255,255));

	//格式数据
	ParaFormat.dwMask=PFM_OFFSETINDENT;
	ParaFormat.dxStartIndent=-200L;

	//还原格式
	SetSel(-1L,-1L);
	SetParaFormat(ParaFormat);

	//恢复信息
	if (CharRange.cpMax!=CharRange.cpMin) SetSel(CharRange);
	else PostMessage(WM_VSCROLL,SB_BOTTOM,0);

	return true;
}
//用户表情
bool CRichEditMessage::InsertExpression(LPCTSTR pszSendUser, LPCTSTR pszImagePath)
{
	//效验参数
	ASSERT((pszImagePath!=NULL)&&(pszImagePath[0]!=0));
	if ((pszImagePath==NULL)||(pszImagePath[0]==0)) return false;

	//插入换行
	LONG lTextLength=GetWindowTextLength();
	if (lTextLength!=0L) InsertString(TEXT("\r\n"),COLOR_EVENT);

	//插入消息
	InsertUserAccounts(pszSendUser);
	InsertString(TEXT("说:"),COLOR_EVENT);

	//插入表情
	InsertImage(pszImagePath);

	return true;
}
/*!
  Load the picture data
  \param format the Picture Format.
  \param image_name the name of the image. Must be unique.
  \param imgProps the RTF properties for the image.
  \return true if success, otherwise false.
  \desc Load the picture data from the flow. Will move the file position
  and assume proper RTF file structure. It will take care of inserting
  the picture into the document.
  \todo TODO: We assume the data comes in hex. Check this assumption
  as we might have to handle binary data as well
  \see IE_Imp_RTF::HandlePicture
*/
bool IE_Imp_RTF::LoadPictData(PictFormat format, const char * image_name,
							  struct RTFProps_ImageProps & imgProps, 
							  bool isBinary, long binaryLen)
{
	// first, we load the actual data into a buffer
	bool ok;
	bool retval = true;

	const UT_uint16 chars_per_byte = 2;
	const UT_uint16 BITS_PER_BYTE = 8;
	const UT_uint16 bits_per_char = BITS_PER_BYTE / chars_per_byte;

	UT_ByteBuf pictData;
	UT_uint16 chLeft = chars_per_byte;
	UT_Byte pic_byte = 0;
	FG_Graphic* pFG = NULL;
	UT_Error error = UT_OK;
	unsigned char ch;

	if (!isBinary) {
		if (!ReadCharFromFile(&ch)) {
			retval = false;
			goto cleanup;
		}

		while (ch != '}')
		{
			int digit;
			
			if (!hexVal(ch, digit)) {
				retval = false;
				goto cleanup;
			}
			
			pic_byte = (pic_byte << bits_per_char) + digit;
			
			// if we have a complete byte, we put it in the buffer
			if (--chLeft == 0)
			{
				pictData.append(&pic_byte, 1);
				chLeft = chars_per_byte;
				pic_byte = 0;
			}
			
			if (!ReadCharFromFile(&ch)) {
				retval = false;
				goto cleanup;
			}
		}
	} else {
		UT_ASSERT_HARMLESS(binaryLen);
		UT_DEBUGMSG(("Loading binary data image of %ld bytes\n", binaryLen));
		for (long i = 0; i < binaryLen; i++) {
			if (!ReadCharFromFileWithCRLF(&ch)) {
				retval = false;
				goto cleanup;
			}
			pictData.append(&ch, 1);
		}
	}

	// We let the caller handle this
	SkipBackChar(ch);

	error = IE_ImpGraphic::loadGraphic(pictData, iegftForRTF(format), &pFG);

	if ((error == UT_OK) && pFG)
	{
		imgProps.width = static_cast<UT_uint32>(pFG->getWidth ());
		imgProps.height = static_cast<UT_uint32>(pFG->getHeight ());
		// Not sure whether this is the right way, but first, we should
		// insert any pending chars
		if (!FlushStoredChars(true))
		{
			UT_DEBUGMSG(("Error flushing stored chars just before inserting a picture\n"));
			DELETEP(pFG);
			return false;
		}

		ok = InsertImage (pFG, image_name, imgProps);
		DELETEP(pFG);
		if (!ok)
		{
			return false;
		}
	}
	else
	{
		// if we're not inserting a graphic, we should destroy the buffer
		UT_DEBUGMSG (("no translator found: %d\n", error));
	}

 cleanup:
	return retval;
}
Ejemplo n.º 6
0
// Inserts an image object in MMS message (this function is provided for backward compatibility)
// Input:	csObjName=String with object name
//			csObjPath=String with file path
void CMMSSender::InsertImage(CString csObjName, CString csObjPath)
{
	InsertImage(csObjPath);
}
Ejemplo n.º 7
0
void Image::InsertImage(const Image* image, const Vector2& dstPos, const Rect& srcRect)
{
	InsertImage(image, (uint32)dstPos.x, (uint32)dstPos.y,
				(uint32)srcRect.x, (uint32)srcRect.y, (uint32)srcRect.dx, (uint32)srcRect.dy);
}