/*
================
CSyntaxRichEditCtrl::Init
================
*/
void CSyntaxRichEditCtrl::Init(void)
{

	// get the Rich Edit ITextDocument to use the wonky TOM interface
	IRichEditOle *ire = GetIRichEditOle();
	IUnknown *iu = (IUnknown *)ire;

	if (iu == NULL || iu->QueryInterface(tom::IID_ITextDocument, (void **) &m_TextDoc) != S_OK) {
		m_TextDoc = NULL;
	}

	InitFont();

	InitSyntaxHighlighting();

	SetEventMask(GetEventMask() | ENM_CHANGE | ENM_KEYEVENTS | ENM_MOUSEEVENTS | ENM_PROTECTED);	// ENM_SCROLLEVENTS

	EnableToolTips(TRUE);

	// create auto complete list box
	CRect rect(0, 0, AUTOCOMPLETE_WIDTH, AUTOCOMPLETE_HEIGHT);
	autoCompleteListBox.Create(WS_DLGFRAME | WS_VISIBLE | WS_VSCROLL | LBS_SORT | LBS_NOTIFY, rect, this, IDC_LISTBOX_AUTOCOMPLETE);
	autoCompleteListBox.SetFont(GetParent()->GetFont());
	autoCompleteListBox.ShowWindow(FALSE);

	// create function parameter tool tip
	funcParmToolTip.Create(WS_VISIBLE | WS_BORDER, rect, this, IDC_EDITBOX_FUNCPARMS);
	funcParmToolTip.SetFont(GetParent()->GetFont());
	funcParmToolTip.ShowWindow(FALSE);
}
Beispiel #2
0
void CEmoticonRichEditCtrl::Initialize() 
{
	PARAFORMAT pf;
	pf.cbSize = sizeof(PARAFORMAT);
	pf.dwMask = PFM_TABSTOPS ;
	pf.cTabCount = MAX_TAB_STOPS;
	for( int itab = 0 ; itab < pf.cTabCount  ; itab++ )
		pf.rgxTabs[itab] = (itab + 1) * 1440/5 ;

	SetParaFormat( pf );		

	SetEventMask(ENM_CHANGE | ENM_SELCHANGE | ENM_PROTECTED);

	//이모티콘		
	m_imgListFaces.Create(20, 20, ILC_COLOR24|ILC_MASK, 0, 1);	
	m_bmpFaces.LoadBitmap(IDB_BITMAP_EMOTICON);
	m_imgListFaces.Add(& m_bmpFaces, RGB(255, 255, 255));	

	m_pRichEditOle = GetIRichEditOle();

	DragAcceptFiles(TRUE);

	/*
	if(m_nRole == ROLE_SEND_INPUT )
	{	
		CHARFORMAT2 cf;
		GetSelectionCharFormat(cf);
		cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE |CFM_PROTECTED ;		
		cf.crTextColor =  CChatSession::Instance().m_ColorMe;			
		cf.dwEffects &=(unsigned long) ~CFE_AUTOCOLOR;	
		SetDefaultCharFormat(cf);			
	}
	*/
	
}
Beispiel #3
0
//创建消息
INT CSkinRichEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (__super::OnCreate(lpCreateStruct)==-1) return -1;

	//初始化控件
	SetEventMask(ENM_LINK);
	SetOptions(ECOOP_OR,ECO_NOHIDESEL);

	//获取接口
	m_pIRichEditOle=GetIRichEditOle();

	return 0;
}
Beispiel #4
0
//控件绑定
VOID CSkinRichEdit::PreSubclassWindow()
{
	__super::PreSubclassWindow();

	//初始化控件
	SetEventMask(ENM_LINK);
	SetOptions(ECOOP_OR,ECO_NOHIDESEL);

	//获取接口
	m_pIRichEditOle=GetIRichEditOle();

	return;
}
Beispiel #5
0
// 测试接口
BOOL tomEdit::TestInsertObject() 
{
    IRichEditOle * rich_edit_ole = GetIRichEditOle() ;
    if (rich_edit_ole == NULL)
        return FALSE ;

    IOleClientSite * obj_client_site = NULL ;
    rich_edit_ole->GetClientSite(&obj_client_site) ;
    if (obj_client_site == NULL)
        return FALSE ;

    m_test_object = new ReImage ;
    m_test_object->SetHost(GetCenter()->GetHost()) ;

    m_object_group.insert(m_test_object) ;

    //m_test_object->InitFromImageFile(_T("C:\\2.gif")) ;
    m_test_object->InitFromImageFile(_T("C:\\x.jpg")) ;
    //m_test_object->SetImagePath(_T("F:\\Program\\Draw\\GetDIBitsUsage\\res\\bitmap1.bmp")) ;
    //m_test_object->SetImagePath(_T("F:\\图片\\风景\\退去喧嚣,我们在路上 - 西藏\\1315471834717.jpg")) ;

    REOBJECT reo;
    memset( &reo, 0, sizeof( reo ) );
    reo.cbStruct = sizeof( reo );

    CLSID classID;
    if ( m_test_object->GetUserClassID( &classID ) != S_OK)
        classID = CLSID_NULL;
    reo.clsid = classID;
    reo.cp = 0;
    reo.poleobj = m_test_object;
    reo.pstg = NULL;
    reo.polesite = obj_client_site ;

//     SIZEL sizel;
//     sizel.cx = DXtoHimetricX(100, s_XPixelPerInch) ;
//     sizel.cy = DYtoHimetricY(80, s_YPixelPerInch) ; // let rich edit determine initial size
//     reo.sizel = sizel;

    reo.sizel.cx = reo.sizel.cy = 0 ;
    reo.dvaspect = DVASPECT_CONTENT;
    reo.dwFlags = REO_BELOWBASELINE /*| REO_RESIZABLE*/ ;
    reo.dwUser = 0 ;
    m_test_object->SetClientSite( obj_client_site );

    HRESULT hr = rich_edit_ole->InsertObject( &reo );

    obj_client_site->Release() ;

    return SUCCEEDED(hr) ;
}
Beispiel #6
0
BOOL tomEdit::TestChangeObjectSize(int cx, int cy) 
{
    IRichEditOle * rich_edit_ole = GetIRichEditOle() ;
    if (rich_edit_ole == NULL)
        return FALSE ;

    m_test_object->AutoAdjustSizeBySpaceWidth(cx) ;
    HRESULT hr = rich_edit_ole->SetDvaspect(0, DVASPECT_CONTENT) ;

//     IOleClientSite * client_site = NULL ;
//     m_test_object->GetClientSite(&client_site) ;

    return SUCCEEDED(hr) ;
}
Beispiel #7
0
// char_position值为REO_CP_SELECTION时表示选择文本被替换为图像对象
// 这里没检测imge_file_path是否有效图片路径
BOOL tomEdit::InsertImageObject(LONG char_position, std::wstring const image_file_path) 
{
    IRichEditOle * rich_edit_ole = GetIRichEditOle() ;
    if (rich_edit_ole == NULL)
        return FALSE ;

    IOleClientSite * obj_client_site = NULL ;
    rich_edit_ole->GetClientSite(&obj_client_site) ;
    if (obj_client_site == NULL)
        return FALSE ;

    ReImage * image = new ReImage ;
    image->SetHost(GetCenter()->GetHost()) ;
    m_object_group.insert(image) ;

    image->InitFromImageFile(image_file_path) ;

    REOBJECT reo;
    memset( &reo, 0, sizeof( reo ) );
    reo.cbStruct = sizeof( reo );

    CLSID classID;
    if ( image->GetUserClassID( &classID ) != S_OK)
        classID = CLSID_NULL;
    reo.clsid = classID;
    reo.cp = char_position ;
    reo.poleobj = image;
    reo.pstg = NULL;
    reo.polesite = obj_client_site ;

    reo.sizel.cx = reo.sizel.cy = 0 ;
    reo.dvaspect = DVASPECT_CONTENT;
    reo.dwFlags = REO_BELOWBASELINE /*| REO_RESIZABLE*/ ;
    reo.dwUser = 0 ;
    image->SetClientSite( obj_client_site );

    HRESULT hr = rich_edit_ole->InsertObject( &reo );

    obj_client_site->Release() ;

    return SUCCEEDED(hr) ;
}
void CExtRichEdit::InsertFace(CString strPicPath)
{
	LPLOCKBYTES lpLockBytes = NULL;
	SCODE sc;
	HRESULT hr;
	//print to RichEdit' s IClientSite
	LPOLECLIENTSITE m_lpClientSite;
	//A smart point to IAnimator
	IGifAnimatorPtr	m_lpAnimator;
	//ptr 2 storage	
	LPSTORAGE m_lpStorage;
	//the object 2 b insert 2
	LPOLEOBJECT	m_lpObject;

	//Create lockbytes
	sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
	if (sc != S_OK)
		AfxThrowOleException(sc);
	ASSERT(lpLockBytes != NULL);
	
	//use lockbytes to create storage
	sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
		STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);
	if (sc != S_OK)
	{
		VERIFY(lpLockBytes->Release() == 0);
		lpLockBytes = NULL;
		AfxThrowOleException(sc);
	}
	ASSERT(m_lpStorage != NULL);
	
	//get the ClientSite of the very RichEditCtrl
	GetIRichEditOle()->GetClientSite(&m_lpClientSite);
	ASSERT(m_lpClientSite != NULL);

	try
	{
		//Initlize COM interface
		hr = ::CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
		if( FAILED(hr) )
			_com_issue_error(hr);
		
		//Get GifAnimator object
		//here, I used a smart point, so I do not need to free it
		hr = m_lpAnimator.CreateInstance(CLSID_GifAnimator);	
		if( FAILED(hr) )
				_com_issue_error(hr);
		//COM operation need BSTR, so get a BSTR
		BSTR path = strPicPath.AllocSysString();

		//Load the gif
		hr = m_lpAnimator->LoadFromFile(path);
		if( FAILED(hr) )
			_com_issue_error(hr);
			
	//	TRACE0( m_lpAnimator->GetFilePath() );
		
		//get the IOleObject
		hr = m_lpAnimator.QueryInterface(IID_IOleObject, (void**)&m_lpObject);
		if( FAILED(hr) )
			_com_issue_error(hr);
		
		//Set it 2 b inserted
		OleSetContainedObject(m_lpObject, TRUE);
		
		//2 insert in 2 richedit, you need a struct of REOBJECT
		REOBJECT reobject;
		ZeroMemory(&reobject, sizeof(REOBJECT));

		reobject.cbStruct = sizeof(REOBJECT);	
		CLSID clsid;
		sc = m_lpObject->GetUserClassID(&clsid);
		if (sc != S_OK)
			AfxThrowOleException(sc);
		//set clsid
		reobject.clsid = clsid;
		//can be selected
		reobject.cp = REO_CP_SELECTION;
		//content, but not static
		reobject.dvaspect = DVASPECT_CONTENT;
		//goes in the same line of text line
		reobject.dwFlags = REO_BELOWBASELINE; //REO_RESIZABLE |
		reobject.dwUser = 0;
		//the very object
		reobject.poleobj = m_lpObject;
		//client site contain the object
		reobject.polesite = m_lpClientSite;
		//the storage 
		reobject.pstg = m_lpStorage;
		
		SIZEL sizel;
		sizel.cx = sizel.cy = 0;
		reobject.sizel = sizel;
		HWND hWndRT = this->m_hWnd;
		//Sel all text
//		::SendMessage(hWndRT, EM_SETSEL, 0, -1);
//		DWORD dwStart, dwEnd;
//		::SendMessage(hWndRT, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
//		::SendMessage(hWndRT, EM_SETSEL, dwEnd+1, dwEnd+1);
		//Insert after the line of text
		GetIRichEditOle()->InsertObject(&reobject);
		::SendMessage(hWndRT, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
		VARIANT_BOOL ret;
		//do frame changing
		ret = m_lpAnimator->TriggerFrameChange();
		//show it
		m_lpObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, m_lpClientSite, 0, m_hWnd, NULL);
		m_lpObject->DoVerb(OLEIVERB_SHOW, NULL, m_lpClientSite, 0, m_hWnd, NULL);
		
		//redraw the window to show animation
		RedrawWindow();

		if (m_lpClientSite)
		{
			m_lpClientSite->Release();
			m_lpClientSite = NULL;
		}
		if (m_lpObject)
		{
			m_lpObject->Release();
			m_lpObject = NULL;
		}
		if (m_lpStorage)
		{
			m_lpStorage->Release();
			m_lpStorage = NULL;
		}
		
		SysFreeString(path);
	}
	catch( _com_error e )
	{
		AfxMessageBox(e.ErrorMessage());
		::CoUninitialize();	
	}
}
void CExRichEditWindowless::InsertGif(LONG gif)
{
	CComQIPtr<IDynamicOleCom> spDyn;
	HRESULT hr = spDyn.CoCreateInstance(STR_PROGID);
	if(SUCCEEDED(hr))
	{
		LPOLEOBJECT lpOleObject = NULL;
		HRESULT hr = spDyn->QueryInterface(IID_IOleObject, (void**)&lpOleObject);

		IUnknownPtr lpUnk = lpOleObject;
		hr = lpUnk->QueryInterface(IID_IOleObject, (LPVOID*)&lpOleObject);
		if (lpOleObject == NULL)
			throw(E_OUTOFMEMORY);
		//hr = lpOleObject->SetClientSite( static_cast<IOleClientSite *>( this ) );
		IViewObject2Ptr lpViewObject;// IViewObject for IOleObject above
		hr = lpOleObject->QueryInterface(IID_IViewObject2, (LPVOID*)&lpViewObject);
		if (hr != S_OK)
		{
			AtlThrow(hr);
		}
		IRichEditOle* pRichEditOle = GetIRichEditOle();
		////获取RichEdit的OLEClientSite
		IOleClientSitePtr lpClientSite;
		hr = pRichEditOle->GetClientSite(&lpClientSite);

		if (hr != S_OK)
		{
			AtlThrow(hr);
		}
		REOBJECT reobject;
		ZeroMemory(&reobject,sizeof(REOBJECT));
		reobject.cbStruct = sizeof(REOBJECT);

		CLSID clsid;
		hr = lpOleObject->GetUserClassID(&clsid);
		if (hr != S_OK)
		{
			AtlThrow(hr);
		}

		reobject.clsid = clsid;
		reobject.cp = -1;
		//reobject.cp = REO_CP_SELECTION;
		reobject.dvaspect = DVASPECT_CONTENT;//DVASPECT_OPAQUE;
		reobject.poleobj = lpOleObject;
		reobject.polesite = lpClientSite;
		//reobject.pstg = lpStorage;
		SIZEL sizel;
		sizel.cx = sizel.cy = 0; // let richedit determine initial size

		Image* img = (Image*)gif;
		SIZEL sizeInPix = {img->GetWidth(), img->GetHeight()};
		SIZEL sizeInHiMetric;
		AtlPixelToHiMetric(&sizeInPix, &sizeInHiMetric);

		reobject.sizel = sizeInHiMetric;
		reobject.dwFlags = REO_BELOWBASELINE|REO_STATIC;//REO_RESIZABLE

		CExRichEditData* pdata = new CExRichEditData;
		pdata->m_dataType = GIF;
		pdata->m_data = (void*)gif;
		reobject.dwUser = (DWORD)pdata;//TODO 用户数据

		lpOleObject->SetClientSite(lpClientSite); 
		hr = pRichEditOle->InsertObject(&reobject);
		lpOleObject->SetExtent(DVASPECT_CONTENT, &sizeInHiMetric);
		OleSetContainedObject(lpOleObject, TRUE);
		lpOleObject->Release();
		spDyn->SetHostWindow((LONG)hwndParent);
		spDyn->InsertGif(gif);
	}
}