CppIEEmbed icon indicating copy to clipboard operation
CppIEEmbed copied to clipboard

keyboard not working

Open NeomMob opened this issue 13 years ago • 1 comments

Hello,

First of all thanks for your code it is very interesting and useful. I am trying to use the following page: http://balexandre.com/jquery/keynav/ but keyboard is not working when displaying the page with CppIEEmbed

Thanks in advance for your help,

NeomMob avatar Jan 03 '12 12:01 NeomMob

Very long issue with those implementations of mshtml, recently used this lib for small test app and added IHTMLEditDesigner to overcome the problem.

class TIHTMLEditDesigner : public IHTMLEditDesigner
{
public:
	virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) {
		HRESULT hrRet = S_OK;
		*ppvObject = NULL;
		if (IsEqualIID(riid, IID_IUnknown))
			*ppvObject = (IUnknown *)this;
		else if (IsEqualIID(riid, IID_IHTMLEditDesigner))
			*ppvObject = (IHTMLEditDesigner *)this;
		else
			hrRet = E_NOINTERFACE;
		if (S_OK == hrRet)
			((IUnknown *)*ppvObject)->AddRef();
		return hrRet;
	}
	virtual ULONG   STDMETHODCALLTYPE AddRef(void) {
		return ++m_uRefCount;
	};
	virtual ULONG   STDMETHODCALLTYPE Release(void) {
		--m_uRefCount;
		if (m_uRefCount == 0) delete this;
		return m_uRefCount;
	};

	virtual HRESULT STDMETHODCALLTYPE PreHandleEvent(DISPID inEvtDispId, IHTMLEventObj *pIEventObj) {
		if (inEvtDispId == DISPID_KEYPRESS) {
			IHTMLElement* ele = NULL;
			if (FAILED(pIEventObj->get_srcElement(&ele))) return S_FALSE;
			VARIANT_BOOL bIsEdit = 0;
			if (FAILED(ele->get_isTextEdit(&bIsEdit))) return S_FALSE;
			ele->Release();
			VARIANT_BOOL bControl = 0;
			if (FAILED(pIEventObj->get_ctrlKey(&bControl))) return S_FALSE;
			if (bControl) {
				long keycode = 0;
				if (FAILED(pIEventObj->get_keyCode(&keycode))) return S_FALSE;
				if (keycode == 3)
					m_webform->GetBrowser()->ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
				if (keycode == 22 && bIsEdit)
					m_webform->GetBrowser()->ExecWB(OLECMDID_PASTE, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
				if (keycode == 24 && bIsEdit)
					m_webform->GetBrowser()->ExecWB(OLECMDID_CUT, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
				if (keycode == 1 && bIsEdit)
					m_webform->GetBrowser()->ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
			}
		}
		return S_FALSE;
	};
	virtual HRESULT STDMETHODCALLTYPE PostHandleEvent(DISPID inEvtDispId, IHTMLEventObj *pIEventObj) {
		return S_FALSE;
	};
	virtual HRESULT STDMETHODCALLTYPE TranslateAccelerator(DISPID inEvtDispId, IHTMLEventObj *pIEventObj) {
		return S_FALSE;
	};
	virtual HRESULT STDMETHODCALLTYPE PostEditorEventNotify(DISPID inEvtDispId, IHTMLEventObj *pIEventObj) {
		return S_FALSE;
	};

	TIHTMLEditDesigner(WebForm* wf) : m_webform(wf) {};
	~TIHTMLEditDesigner() {};

private:
	ULONG m_uRefCount = 0;
	WebForm* m_webform;
};

To integrate it, ive added at the end of WebForm::AddCustomObject

IHTMLEditServices* m_pServices = NULL;;
	IServiceProvider *pTemp;
	TIHTMLEditDesigner* cdes = new TIHTMLEditDesigner(this);
	if (doc == (IHTMLDocument2 *)NULL)
		return;
	doc->QueryInterface(IID_IServiceProvider, (void **)&pTemp);
	if (pTemp != (IServiceProvider *)NULL)
	{
		pTemp->QueryService(SID_SHTMLEditServices, IID_IHTMLEditServices, (void **)&m_pServices);
		if (m_pServices != (IHTMLEditServices *)NULL)
		{
			m_pServices->AddDesigner(cdes);
		}
	}
	doc->Release();

This example will enable usage of copy, paste, cut and select all with its accelerators, but could be used for anything key related.

pabloko avatar Apr 15 '20 15:04 pabloko