BOOL IsActiveElementEdit(CComQIPtr<IHTMLDocument2>& spDocument)
{
BOOL bEditMode = FALSE;
if(spDocument)
{
/*BSTR p = NULL;
spDocument->get_designMode(&p);
CString strDesignMode = p;
if(strDesignMode.CompareNoCase(_T("On")) == 0)
{
bEditMode = TRUE;
}*/
/*CComQIPtr<IDisplayServices> spDisplayServices = spDocument;
if(spDisplayServices)
{
CComPtr<IHTMLCaret> spCaret;
spDisplayServices->GetCaret(&spCaret);
if(spCaret)
{
BOOL bCaretVisible = FALSE;
spCaret->IsVisible(&bCaretVisible);
bEditMode = bCaretVisible;
}
}*/
if(!bEditMode)
{
CComPtr<IHTMLElement> spElement;
spDocument->get_activeElement(&spElement);
if(spElement)
{
/*VARIANT_BOOL bTextEdit = FALSE;
spElement->get_isTextEdit(&bTextEdit);
bEditMode = bTextEdit;*/
if(!bEditMode)
{
CComQIPtr<IHTMLElement3> spElement3 = spElement;
if(spElement3)
{
VARIANT_BOOL bEditable = FALSE;
spElement3->get_isContentEditable(&bEditable);
bEditMode = bEditable;
}
}
/*CComQIPtr<IHTMLElementDefaults> spElementDefaults = spElement;
if(spElementDefaults)
{
BSTR p = NULL;
spElementDefaults->get_contentEditable(&p);
CString strEditable = p;
}*/
if(!bEditMode)
{
CComBSTR bstrTagName;
spElement->get_tagName(&bstrTagName);
/*if (lstrcmpiW(L"TEXTAREA", bstrTagName) == 0)
{
bEditMode = TRUE;
}
else if (lstrcmpiW(L"DIV", bstrTagName) == 0)
{
}
else */if (lstrcmpiW(L"IFRAME", bstrTagName) == 0 || lstrcmpiW(L"FRAME", bstrTagName) == 0)
{
/*CComPtr<IDispatch> spDispDocument;
spElement->get_document(&spDispDocument);
if(spDispDocument)
{
CComQIPtr<IHTMLDocument2> spFrameDocument = spDispDocument;
if(spFrameDocument)
{
bEditMode = IsActiveElementEdit(spFrameDocument);
}
}*/
/*CComQIPtr<IHTMLFrameBase2> spFrameBase(spElement);
if(spFrameBase)
{
CComPtr<IHTMLWindow2> spFrameWindow;
spFrameBase->get_contentWindow(&spFrameWindow);
if(spFrameWindow)
{
CComQIPtr<IHTMLDocument2> spFrameDocument;
spFrameWindow->get_document(&spFrameDocument);
if(!spFrameDocument)
{
CComQIPtr<IServiceProvider> spServiceProvider(spFrameWindow);
if (spServiceProvider)
{
CComPtr<IWebBrowser2> spWebBrowser;
spServiceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&spWebBrowser);
if(spWebBrowser)
{
CComPtr<IDispatch> spDispDocument;
spWebBrowser->get_Document(&spDispDocument);
spFrameDocument = spDispDocument;
}
}
}
bEditMode = IsActiveElementEdit(spFrameDocument);
}
}*/
}
}
}
}
}
return bEditMode;
}