brjcomponent.cpp
来自「java调用ie浏览器demo源码,可以用在windows或者linux」· C++ 代码 · 共 1,409 行 · 第 1/3 页
CPP
1,409 行
OLE_HRT( pThis->GetThread()->MakeAction(
env,
"Browser JScript execution error",
a));
LPCTSTR lpRes = a.m_bsResult;
return JNU_NewStringPlatform(env, lpRes ? lpRes : _T(""));
OLE_CATCH
}
return 0;
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: setURL
* Signature: (Ljava/lang/String;)V
*/
struct SetURLAction : public BrowserAction{
JStringBuffer m_jstURL;
BrJComponent *m_pThis;
jobject m_jisURL;
SetURLAction(
BrJComponent *pThis,
JNIEnv *env,
jstring jURL,
jobject jisURL
):m_pThis(pThis),
m_jstURL(env, jURL),
m_jisURL(makeGlobal(env, jisURL))
{}
virtual HRESULT Do(JNIEnv *env)
{
OLE_TRY
OLE_HRT( m_pThis->Connect(_B(m_jstURL), env, m_jisURL) )
OLE_CATCH_ALL
if(!repeatOnError(OLE_HR)){
releaseGlobal(env, m_jisURL);
}
OLE_RETURN_HR
}
};
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_setURL(
JNIEnv *env,
jobject self,
jstring jsURL,
jobject jisURL)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
pThis->GetThread()->MakeAction(
env,
"URL navigation error",
SetURLAction(
pThis,
env,
jsURL,
jisURL));
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: laizyUpdate
* Signature: (jint)
*/
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_laizyUpdate(
JNIEnv *env,
jobject self,
jint msDelay)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
pThis->LaizyUpdate(msDelay);
}
}
struct UpdateTransparentAction : public BrowserAction
{
BrJComponent *m_pThis;
RECT m_rc;
UpdateTransparentAction(
BrJComponent *pThis,
jint x, jint y, jint w, jint h
):m_pThis(pThis)
{
m_rc.left = x;
m_rc.top = y;
m_rc.right = m_rc.left + w;
m_rc.bottom = m_rc.top + h;
}
virtual HRESULT Do(JNIEnv *env)
{
m_pThis->updateTransparentMask(/*&m_rc*/NULL);
return S_OK;
}
};
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: updateTransparentMask
*/
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_updateTransparentMask(
JNIEnv *env,
jobject self,
jint x, jint y, jint w, jint h)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
//pThis->updateTransparentMask();
pThis->GetThread()->MakeAction(
env,
"updateTransparentMask error",
UpdateTransparentAction(pThis, x, y, w, h)
);
}
}
struct SetTransparentAction : public BrowserAction
{
BrJComponent *m_pThis;
jboolean m_transparent;
SetTransparentAction(
BrJComponent *pThis,
jboolean transparent
):m_pThis(pThis),
m_transparent(transparent)
{}
virtual HRESULT Do(JNIEnv *env)
{
m_pThis->setTransparent(m_transparent);
return S_OK;
}
};
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: setTransparent
*/
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_nativeSetTransparent(
JNIEnv *env,
jobject self,
jboolean transparent)
{
SEP0(_T("nativeSetTransparent"))
//STRACE1(_T("nativeSetTransparent %d"), transparent);
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
//pThis->setTransparent(transparent);
pThis->GetThread()->MakeAction(
env,
"nativeSetTransparent error",
SetTransparentAction(pThis, transparent)
);
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: setVisible
*/
struct ShowAction : public BrowserAction
{
BrJComponent *m_pThis;
BOOL bShow;
ShowAction(
BrJComponent *pThis,
BOOL _bShow
):m_pThis(pThis),
bShow(_bShow)
{}
virtual HRESULT Do(JNIEnv *env)
{
::ShowWindow(m_pThis->GetTopWnd(), bShow ? SW_SHOW : SW_HIDE );
return S_OK;
}
};
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_setVisible(
JNIEnv *env,
jobject self,
jboolean aFlag)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
pThis->GetThread()->MakeAction(
env,
"ShowWindow error",
ShowAction(
pThis,
aFlag));
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: setEnabled
*/
struct EnableAction : public BrowserAction
{
BrJComponent *m_pThis;
BOOL bEnable;
EnableAction(
BrJComponent *pThis,
BOOL _bEnable
):m_pThis(pThis),
bEnable(_bEnable)
{}
virtual HRESULT Do(JNIEnv *env)
{
::EnableWindow(m_pThis->GetTopWnd(), bEnable);
return S_OK;
}
};
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_setEnabled(
JNIEnv *env,
jobject self,
jboolean enabled)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
pThis->GetThread()->MakeAction(
env,
"EnableWindow error",
EnableAction(
pThis,
enabled));
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: nativeDraw
*/
struct NativeDrawAction : public BrowserAction
{
BrJComponent *m_pThis;
RECT m_rcDraw;
BOOL m_bToImage;
jintArray m_jaiPoints;
NativeDrawAction(
BrJComponent *pThis,
jint x, jint y, jint w, jint h,
BOOL bToImage
):m_pThis(pThis),
m_bToImage(bToImage),
m_jaiPoints(NULL)
{
SetRect(&m_rcDraw, x, y, x + w, y + h);
}
virtual HRESULT Do(JNIEnv *env)
{
m_jaiPoints = m_pThis->NativeDraw(&m_rcDraw, m_bToImage);
return S_OK;
}
};
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_nativeDraw(
JNIEnv *env,
jobject self,
jint x, jint y, jint w, jint h)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
pThis->GetThread()->MakeAction(
env,
"Native Draw error",
NativeDrawAction(
pThis,
x, y, w, h, FALSE));
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: ImageData
*/
JNIEXPORT jintArray JNICALL Java_org_jdic_web_peer_WBrComponentPeer_ImageData(
JNIEnv *env,
jobject self,
jint x, jint y, jint w, jint h)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
OLE_TRY
NativeDrawAction a(
pThis,
x, y, w, h, true);
OLE_HRT(pThis->GetThread()->MakeAction(
env,
"Native Draw error",
a));
jintArray jaiColors = (jintArray)env->NewLocalRef(a.m_jaiPoints);
env->DeleteGlobalRef(a.m_jaiPoints);
return jaiColors;
OLE_CATCH
}
return NULL;
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: nativePosOnScreen
*/
struct ReshapeAction : public BrowserAction
{
BrJComponent *m_pThis;
jint x, y, w, h;
ReshapeAction(
BrJComponent *pThis,
jint _x, jint _y, jint _w, jint _h
):m_pThis(pThis),
x(_x), y(_y), w(_w), h(_h)
{}
virtual HRESULT Do(JNIEnv *env)
{
MoveWindow(m_pThis->GetTopWnd(), x, y, w, h, FALSE);
return S_OK;
}
};
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_nativePosOnScreen(
JNIEnv *env,
jobject self,
jint x, jint y, jint w, jint h)
{
SEP0(_T("nativePosOnScreen"))
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
STRACE0(_T("nativePosOnScreen x:%d y:%d w:%d h:%d"), x, y, w, h);
POINT pt = {x, y};
MapWindowPoints(
NULL,
pThis->GetParent(),
&pt,
1);
if( -1==w || -1==h){
RECT rc;
GetWindowRect(pThis->GetTopWnd(), &rc);
if( -1==w ){
w = rc.right - rc.left;
}
if( -1==h ){
h = rc.bottom - rc.top;
}
}
pThis->GetThread()->MakeAction(
env,
"Reshape error",
ReshapeAction(
pThis,
pt.x, pt.y, w, h)
);
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: clearRgn
*/
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_clearRgn(
JNIEnv *env,
jobject self)
{
SEP0(_T("clearRgn"))
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis && pThis->m_hChildArea){
DeleteObject((HGDIOBJ)pThis->m_hChildArea);
pThis->m_hChildArea = CreateRectRgn(0,0,0,0);
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: clearRgn
*/
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_clipChild(
JNIEnv *env,
jobject self,
jint x, jint y, jint w, jint h)
{
SEP0(_T("clipChild"))
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis ){
HRGN rg = CreateRectRgn(x, y, x+w, y+h);
if(NULL!=rg){
CombineRgn(
pThis->m_hChildArea,
pThis->m_hChildArea,
rg,
RGN_OR
);
DeleteObject((HGDIOBJ)rg);
}
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: blockNativeInputHandler
*/
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_blockNativeInputHandler(
JNIEnv *env,
jobject self,
jboolean bBlockNativeInputHandler)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
pThis->m_bBlockNativeInputHandler = bBlockNativeInputHandler;
}
}
/*
* Class: org_jdic_web_peer_WBrComponentPeer
* Method: nativeSendMouseEvent
*/
const static int WND_TOP = 0;
const static int WND_PARENT = 1;
const static int WND_IE = 2;
JNIEXPORT jlong JNICALL Java_org_jdic_web_peer_WBrComponentPeer_nativeSendMouseEvent(
JNIEnv *env,
jobject self,
jint wnd, jint wm, jint wParam, jint lParam)
{
jlong ret = 0;
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis){
HWND hWnd = (WND_PARENT==wnd) ? pThis->GetParent() : pThis->GetIEWnd();
if(hWnd){
ret = (jlong)::SendMessage(hWnd, (UINT)wm, (WPARAM)wParam, (LPARAM)lParam);
}
}
return ret;
}
JNIEXPORT void JNICALL Java_org_jdic_web_peer_WBrComponentPeer_nativeReleaseMouseCapture(
JNIEnv *env,
jobject self)
{
jlong ret = 0;
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
//if( pThis && pThis->GetParent()==GetCapture() ){
if(!ReleaseCapture()){
STRACE1(_T("Error:ReleaseCapture"));
}
}
JNIEXPORT jint JNICALL Java_org_jdic_web_peer_WBrComponentPeer_setActionFiler(
JNIEnv *env,
jobject self,
jint flag, jboolean busyState)
{
BrJComponent *pThis = (BrJComponent *)env->GetLongField(self, BrJComponent::ms_jcidWBrComponentPeer_data);
if(pThis ){
pThis->GetThread()->SetBusy( BOOL(busyState) );
}
return 0;
}
} /* extern "C" */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?