www.pudn.com > SimpleInput.rar > InputMethod.cpp


// InputMethod.cpp: implementation of the CInputMethod class. 
// 
////////////////////////////////////////////////////////////////////// 
#include "stdafx.h" 
#include "InputMethod.h" 
#include "Common.h" 
#include "configure.h" 
#include "Userdefinedmessage.h" 
 
//-------------------------------------------------------------------- 
//Macro define 
#define SIP_WND_WIDTH			200 
#define SIP_WND_HEIGHT			180 
//---------------------------------------------------------------------- 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CInputMethod::CInputMethod(long *plDllCnt, HINSTANCE hInst) 
{	 
	GETINSTANCE();	 
	m_hInst = hInst; 
	m_plDllCnt = plDllCnt; 
	(*m_plDllCnt)++; 
	m_lRef = 1;     // Set ref count to 1 on create. 
 
 
#ifdef IMWND_FROM_DLL 
	 
	GETWINDOW = NULL; 
	SHOWUSEROPTIONSDLG = NULL; 
	SHOWWINDOW = NULL; 
	DESTROYWINDOW = NULL; 
	INITIALIZE = NULL; 
 
	HINSTANCE hInstDll; 
	hInstDll = LoadLibrary(IMWND_DLL_PATH); 
	if(hInstDll != NULL) 
	{ 
		GETWINDOW = (DLL_GETWINDOW) GetProcAddress(hInstDll,TEXT("IMGetWindow")); 
		SHOWUSEROPTIONSDLG = (DLL_SHOWUSEROPTIONSDLG) GetProcAddress(hInstDll,TEXT("IMShowUserOptionsDlg")); 
		SHOWWINDOW = (DLL_SHOWWINDOW) GetProcAddress(hInstDll,TEXT("IMShowWindow")); 
		DESTROYWINDOW = (DLL_DESTROYWINDOW) GetProcAddress(hInstDll,TEXT("IMDestroyWindow")); 
		INITIALIZE = (DLL_INITIALIZE) GetProcAddress(hInstDll,TEXT("IMInitialize")); 
	} 
 
	if(GETWINDOW == NULL || 
		SHOWUSEROPTIONSDLG == NULL || 
		SHOWWINDOW == NULL || 
		DESTROYWINDOW == NULL || 
		INITIALIZE == NULL ) 
	{ 
		m_bLoadLib = FALSE; 
	} 
	else 
	{ 
		m_bLoadLib = TRUE; 
	} 
 
#endif 
 
} 
 
CInputMethod::~CInputMethod() 
{ 
	(*m_plDllCnt)--; 
} 
 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to create the windows and image list for the input method (IM). 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::Select(HWND hWndSip) 
{ 
	WRITELOG("CInputMethod::Select()"); 
	 
	if(INITIALIZE(m_hInst,hWndSip) == FALSE) 
	{ 
		WRITELOG("CInputMethod::Select--> E_FAIL"); 
 
		return E_FAIL; 
	} 
 
	SHOWWINDOW(TRUE); 
 
	WRITELOG("CInputMethod::Select--> S_OK"); 
 
	return S_OK; 
} 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to select the input method (IM) out of the software-based  
//input panel window and to destroy the IM windows.  
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::Deselect() 
{ 
	WRITELOG("CInputMethod::Deselect()"); 
 
	DESTROYWINDOW(); 
	return S_OK; 
} 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to perform any initialization before the software-based  
//input panel window is displayed 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::Showing() 
{ 
	WRITELOG("CInputMethod::Showing()"); 
 
	SHOWWINDOW(TRUE); 
	return S_OK; 
} 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to perform any saving routines before the software-based  
//input panel is hidden. 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::Hiding() 
{ 
	WRITELOG("CInputMethod::Hiding()"); 
 
	SHOWWINDOW(FALSE); 
 
	return S_OK; 
} 
 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to return information about the current input  
//method (IM) to the operating system. 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::GetInfo(IMINFO *pimi) 
{ 
	WRITELOG("CInputMethod::GetInfo()"); 
 
	pimi->cbSize = sizeof (IMINFO); 
	pimi->hImageNarrow = 0; 
	pimi->hImageWide = 0; 
	pimi->iNarrow = 0; 
	pimi->iWide = 0;   
	pimi->fdwFlags = SIPF_DOCKED; 
 
	pimi->rcSipRect.left = 0; 
	pimi->rcSipRect.top = 0; 
	pimi->rcSipRect.right = SIP_WND_WIDTH; 
	pimi->rcSipRect.bottom = SIP_WND_HEIGHT; 
	return S_OK; 
} 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented for the IM to receive information about the size, 
//placement, and docked status of the software-based input panel. 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::ReceiveSipInfo(SIPINFO *psi) 
{ 
	WRITELOG("CInputMethod::ReceiveSipInfo()"); 
 
	return S_OK; 
} 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to receive a pointer to an IIMCallback interface.  
//An input method (IM) uses the IIMCallback interface to send keystrokes to applications  
//and to change the icons on the Input Panel button. 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::RegisterCallback(IIMCallback *pIMCallback) 
{ 
	WRITELOG("CInputMethod::RegisterCallback()"); 
 
	//Tell the IM window to register the callback 
	HWND hWnd = GETWINDOW(); 
	SendMessage(hWnd,MYMSG_REGCALLBACK,(WPARAM)pIMCallback,0); 
	return S_OK; 
} 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to send data from the current  
//input method (IM) to the current application. 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::GetImData(DWORD dwSize, void *pvImData) 
{ 
	WRITELOG("CInputMethod::GetImData()"); 
 
	return S_OK; 
} 
 
//------------------------------------------------------------------------------------------- 
//Description: 
//	This method is implemented to respond to an application's request to  
//set input method (IM)-specific data within the IM. 
//---------------------------------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::SetImData(DWORD dwSize, void *pvImData) 
{ 
	WRITELOG("CInputMethod::SetImData()"); 
 
	return S_OK; 
} 
 
//--------------------------------------------------------------------- 
//Description: 
//	Increment object ref count 
//---------------------------------------------------------------------- 
STDMETHODIMP CInputMethod::QueryInterface(REFIID riid, LPVOID *ppv) 
{ 
	WRITELOG("CInputMethod::QueryInterface()"); 
 
 
#ifdef IMWND_FROM_DLL 
	if(m_bLoadLib == FALSE) 
	{ 
		WRITELOG("Failed in loading the IMWnd Dll"); 
		return E_NOINTERFACE; 
	} 
#endif //#ifdef IMWND_FROM_DLL 
 
 
	// If caller wants our IUnknown or IID_IInputMethod2 object,  
	// return a pointer to the object. 
    if (IsEqualIID (riid, IID_IUnknown) || IsEqualIID (riid, IID_IInputMethod) || IsEqualIID (riid, IID_IInputMethod2)) 
	{ 
        // Return ptr to object. 
        *ppv = (IInputMethod *)this; 
        AddRef();                // Increment ref to prevent delete on return. 
        return NOERROR; 
    } 
    *ppv = NULL; 
    return (E_NOINTERFACE); 
 
} 
 
 
//--------------------------------------------------------------------- 
//Description: 
//	Increment object ref count 
//---------------------------------------------------------------------- 
STDMETHODIMP_(ULONG) CInputMethod::AddRef() 
{ 
	WRITELOG("CInputMethod::AddRef()"); 
    
	ULONG cnt;    
    cnt = (ULONG)InterlockedIncrement (&m_lRef); 
    return cnt; 
} 
 
//--------------------------------------------------------------------- 
//Description: 
//	Increment object ref count 
//---------------------------------------------------------------------- 
STDMETHODIMP_(ULONG) CInputMethod::Release() 
{ 
	WRITELOG("CInputMethod::Release()"); 
 
    ULONG cnt; 
    
    cnt = (ULONG)InterlockedDecrement (&m_lRef); 
    if (cnt == 0)  
	{ 
        delete this; 
        return 0; 
    } 
    return cnt; 
} 
 
 
//--------------------------------------------------------------------- 
//Description: 
//	The SIP Control Panel applet is asking for a configuration dialog box to be displayed. 
//---------------------------------------------------------------------- 
HRESULT STDMETHODCALLTYPE CInputMethod::UserOptionsDlg(HWND hwndParent) 
{ 
	WRITELOG("CInputMethod::UserOptionsDlg()"); 
 
	SHOWUSEROPTIONSDLG(hwndParent,m_hInst); 
	return S_OK; 
}