// Create a new AwtChoice object and window. AwtChoice* AwtChoice::Create( jobject peer, jobject hParent ) { JNIEnv *env; if ( JVM->AttachCurrentThread( (void **)&env, 0 ) != 0 ) { return 0; } CHECK_NULL_RETURN( hParent, "null hParent" ); AwtCanvas *parent = PDATA( AwtCanvas, hParent ); CHECK_NULL_RETURN( parent, "null parent" ); jobject target = env->GetObjectField( peer, WCachedIDs.PPCObjectPeer_targetFID ); CHECK_NULL_RETURN( target, "null target" ); AwtChoice *c = new AwtChoice(); CHECK_NULL_RETURN( c, "AwtChoice() failed" ); #ifndef WINCE DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED; #else // WINCE does not support OWNERDRAW combo boxes. DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | CBS_DROPDOWNLIST; #endif // !WINCE // In OWNER_DRAW, the size of the edit control part of the choice // must be determinded in its creation, when the parent cannot get // the choice's instance from its handle. So record the pair of // the ID and the instance of the choice. UINT myId = parent->CreateControlID(); ASSERT( myId > 0 ); c->m_myControlID = myId; parent->PushChild( myId, c ); c->CreateHWnd( TEXT(""), style, 0, env->CallIntMethod( target, WCachedIDs.java_awt_Component_getXMID ), env->CallIntMethod( target, WCachedIDs.java_awt_Component_getYMID ), env->CallIntMethod( target, WCachedIDs.java_awt_Component_getWidthMID ), env->CallIntMethod( target, WCachedIDs.java_awt_Component_getHeightMID ), parent->GetHWnd(), (HMENU)myId, ::GetSysColor( COLOR_WINDOWTEXT ), ::GetSysColor( COLOR_WINDOW ), peer ); c->m_backgroundColorSet = TRUE; // suppress inheriting parent's color. return c; }
AwtChoice* AwtChoice::Create(jobject peer, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtChoice* c = NULL; RECT rc; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } AwtCanvas* awtParent; JNI_CHECK_NULL_GOTO(parent, "null parent", done); awtParent = (AwtCanvas*)JNI_GET_PDATA(parent); JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); target = env->GetObjectField(peer, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); c = new AwtChoice(); { DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED; DWORD exStyle = 0; if (GetRTL()) { exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; } /* * In OWNER_DRAW, the size of the edit control part of the * choice must be determinded in its creation, when the parent * cannot get the choice's instance from its handle. So * record the pair of the ID and the instance of the choice. */ UINT myId = awtParent->CreateControlID(); DASSERT(myId > 0); c->m_myControlID = myId; awtParent->PushChild(myId, c); jint x = env->GetIntField(target, AwtComponent::xID); jint y = env->GetIntField(target, AwtComponent::yID); jint width = env->GetIntField(target, AwtComponent::widthID); jint height = env->GetIntField(target, AwtComponent::heightID); jobject dimension = JNU_CallMethodByName(env, NULL, peer, "preferredSize", "()Ljava/awt/Dimension;").l; DASSERT(!safe_ExceptionOccurred(env)); if (dimension != NULL && width == 0) { width = env->GetIntField(dimension, AwtDimension::widthID); } c->CreateHWnd(env, L"", style, exStyle, x, y, width, height, awtParent->GetHWnd(), reinterpret_cast<HMENU>(static_cast<INT_PTR>(myId)), ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), peer); /* suppress inheriting parent's color. */ c->m_backgroundColorSet = TRUE; c->UpdateBackground(env, target); /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match * actual size * Fix: Set the Choice to its actual size in the component. */ ::GetClientRect(c->GetHWnd(), &rc); env->SetIntField(target, AwtComponent::widthID, (jint) rc.right); env->SetIntField(target, AwtComponent::heightID, (jint) rc.bottom); env->DeleteLocalRef(dimension); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return c; }