/* Create a new AwtLabel object and window. */ AwtLabel* AwtLabel::Create(jobject labelPeer, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtLabel* awtLabel = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } PDATA pData; AwtCanvas* awtParent; JNI_CHECK_PEER_GOTO(parent, done); awtParent = (AwtCanvas*)pData; JNI_CHECK_NULL_GOTO(awtParent, "awtParent", done); target = env->GetObjectField(labelPeer, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "target", done); awtLabel = new AwtLabel(); { DWORD style = WS_CHILD | WS_CLIPSIBLINGS; DWORD exStyle = 0; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; 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); awtLabel->CreateHWnd(env, L"", style, exStyle, x, y, width, height, awtParent->GetHWnd(), NULL, ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_BTNFACE), labelPeer); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return awtLabel; }
void AwtList::_AddItems(void *param) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); AddItemsStruct *ais = (AddItemsStruct *)param; jobject self = ais->list; jobjectArray items = ais->items; jint index = ais->index; jint width = ais->width; int badAlloc = 0; AwtList *l = NULL; PDATA pData; JNI_CHECK_PEER_GOTO(self, ret); JNI_CHECK_NULL_GOTO(items, "null items", ret); l = (AwtList*)pData; if (::IsWindow(l->GetHWnd())) { int itemCount = env->GetArrayLength(items); if (itemCount > 0) { AwtList* l = (AwtList*)pData; l->SendListMessage(WM_SETREDRAW, (WPARAM)FALSE, 0); for (jsize i=0; i < itemCount; i++) { LPTSTR itemPtr = NULL; jstring item = (jstring)env->GetObjectArrayElement(items, i); if (env->ExceptionCheck()) goto ret; if (item == NULL) goto next_item; itemPtr = (LPTSTR)JNU_GetStringPlatformChars(env, item, 0); if (itemPtr == NULL) { badAlloc = 1; } else { l->InsertString(index+i, itemPtr); JNU_ReleaseStringPlatformChars(env, item, itemPtr); } env->DeleteLocalRef(item); next_item: ; } l->SendListMessage(WM_SETREDRAW, (WPARAM)TRUE, 0); l->InvalidateList(NULL, TRUE); l->CheckMaxWidth(width); } } ret: env->DeleteGlobalRef(self); env->DeleteGlobalRef(items); delete ais; if (badAlloc) { throw std::bad_alloc(); } }
void AwtMenuBar::_AddMenu(void *param) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); AddMenuStruct *ams = (AddMenuStruct *)param; jobject self = ams->menubar; jobject menu = ams->menu; AwtMenuBar *m = NULL; PDATA pData; JNI_CHECK_PEER_GOTO(self, ret); JNI_CHECK_NULL_GOTO(menu, "null menu", ret); m = (AwtMenuBar *)pData; if (::IsWindow(m->GetOwnerHWnd())) { /* The menu was already created and added during peer creation -- redraw */ m->RedrawMenuBar(); } ret: env->DeleteGlobalRef(self); if (menu != NULL) { env->DeleteGlobalRef(menu); } delete ams; }
/* Create a new AwtPopupMenu object and menu. */ AwtPopupMenu* AwtPopupMenu::Create(jobject self, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtPopupMenu* popupMenu = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } JNI_CHECK_NULL_GOTO(parent, "peer", done); AwtComponent* awtParent = (AwtComponent*) JNI_GET_PDATA(parent); target = env->GetObjectField(self, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); popupMenu = new AwtPopupMenu(); SetLastError(0); HMENU hMenu = ::CreatePopupMenu(); // fix for 5088782 if (!CheckMenuCreation(env, self, hMenu)) { env->DeleteLocalRef(target); return NULL; } popupMenu->SetHMenu(hMenu); popupMenu->LinkObjects(env, self); popupMenu->SetParent(awtParent); } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return popupMenu; }
/* Create a new AwtMenuBar object and menu. */ AwtMenuBar* AwtMenuBar::Create(jobject self, jobject framePeer) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtMenuBar* menuBar = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } /* target is a java.awt.MenuBar */ target = env->GetObjectField(self, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); menuBar = new AwtMenuBar(); SetLastError(0); HMENU hMenu = ::CreateMenu(); // fix for 5088782 if (!CheckMenuCreation(env, self, hMenu)) { env->DeleteLocalRef(target); return NULL; } menuBar->SetHMenu(hMenu); menuBar->LinkObjects(env, self); if (framePeer != NULL) { PDATA pData; JNI_CHECK_PEER_GOTO(framePeer, done); menuBar->m_frame = (AwtFrame *)pData; } else { menuBar->m_frame = NULL; } } catch (...) { env->DeleteLocalRef(target); throw; } done: if (target != NULL) { env->DeleteLocalRef(target); } return menuBar; }
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; }
/* Create a new AwtTextArea or AwtTextField object and window. */ AwtTextComponent* AwtTextComponent::Create(jobject peer, jobject parent, BOOL isMultiline) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtTextComponent* c = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } PDATA pData; AwtCanvas* awtParent; JNI_CHECK_PEER_GOTO(parent, done); awtParent = (AwtCanvas*)pData; JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); target = env->GetObjectField(peer, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); if(isMultiline) { c = new AwtTextArea(); } else { c = new AwtTextField(); } { /* Adjust style for scrollbar visibility and word wrap */ DWORD scroll_style; if(isMultiline) { jint scrollbarVisibility = env->GetIntField(target, AwtTextArea::scrollbarVisibilityID); switch (scrollbarVisibility) { case java_awt_TextArea_SCROLLBARS_NONE: scroll_style = ES_AUTOVSCROLL; break; case java_awt_TextArea_SCROLLBARS_VERTICAL_ONLY: scroll_style = WS_VSCROLL | ES_AUTOVSCROLL; break; case java_awt_TextArea_SCROLLBARS_HORIZONTAL_ONLY: scroll_style = WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL; break; case java_awt_TextArea_SCROLLBARS_BOTH: scroll_style = WS_VSCROLL | WS_HSCROLL | ES_AUTOVSCROLL | ES_AUTOHSCROLL; break; } } DWORD style = WS_CHILD | WS_CLIPSIBLINGS | ES_LEFT; /* * Specify ES_DISABLENOSCROLL - RichEdit control style to disable * scrollbars instead of hiding them when not needed. */ style |= isMultiline ? ES_MULTILINE | ES_WANTRETURN | scroll_style | ES_DISABLENOSCROLL : ES_AUTOHSCROLL; DWORD exStyle = WS_EX_CLIENTEDGE; if (GetRTL()) { exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; } 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); c->CreateHWnd(env, L"", style, exStyle, x, y, width, height, awtParent->GetHWnd(), reinterpret_cast<HMENU>(static_cast<INT_PTR>( awtParent->CreateControlID())), ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), peer); // Fix for 4753116. // If it is not win95 (we are using Richedit 2.0) // we set plain text mode, in which the control is // similar to a standard edit control: // - The text in a plain text control can have only // one format. // - The user cannot paste rich text formats, such as RTF // or embedded objects into a plain text control. // - Rich text mode controls always have a default // end-of-document marker or carriage return, // to format paragraphs. // [email protected] c->SendMessage(EM_SETTEXTMODE, TM_PLAINTEXT, 0); c->m_backgroundColorSet = TRUE; /* suppress inheriting parent's color. */ c->UpdateBackground(env, target); c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELPARAM(1, 1)); /* * Fix for BugTraq Id 4260109. * Set the text limit to the maximum. * Use EM_EXLIMITTEXT for RichEdit controls. * For some reason RichEdit 1.0 becomes read-only if the * specified limit is greater than 0x7FFFFFFD. */ c->SendMessage(EM_EXLIMITTEXT, 0, 0x7FFFFFFD); /* Unregister RichEdit built-in drop target. */ VERIFY(::RevokeDragDrop(c->GetHWnd()) != DRAGDROP_E_INVALIDHWND); /* To enforce CF_TEXT format for paste operations. */ VERIFY(c->SendMessage(EM_SETOLECALLBACK, 0, (LPARAM)&GetOleCallback())); c->SendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return c; }
/* Create a new AwtScrollbar object and window. */ AwtScrollbar * AwtScrollbar::Create(jobject peer, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtScrollbar* c = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } PDATA pData; AwtCanvas* awtParent; JNI_CHECK_PEER_GOTO(parent, done); awtParent = (AwtCanvas*)pData; JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); target = env->GetObjectField(peer, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); c = new AwtScrollbar(); { jint orientation = env->GetIntField(target, AwtScrollbar::orientationID); c->m_orientation = (orientation == java_awt_Scrollbar_VERTICAL) ? SB_VERT : SB_HORZ; c->m_lineIncr = env->GetIntField(target, AwtScrollbar::lineIncrementID); c->m_pageIncr = env->GetIntField(target, AwtScrollbar::pageIncrementID); DWORD style = WS_CHILD | WS_CLIPSIBLINGS | c->m_orientation;/* Note: SB_ and SBS_ are the same here */ 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); c->CreateHWnd(env, L"", style, 0, x, y, width, height, awtParent->GetHWnd(), reinterpret_cast<HMENU>(static_cast<INT_PTR>( awtParent->CreateControlID())), ::GetSysColor(COLOR_SCROLLBAR), ::GetSysColor(COLOR_SCROLLBAR), peer); c->m_backgroundColorSet = TRUE; /* suppress inheriting parent's color. */ c->UpdateBackground(env, target); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return c; }
/* Create a new AwtScrollPane object and window. */ AwtScrollPane* AwtScrollPane::Create(jobject self, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtScrollPane* c = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } PDATA pData; AwtComponent* awtParent; JNI_CHECK_PEER_GOTO(parent, done); awtParent = (AwtComponent*)pData; JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); target = env->GetObjectField(self, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); c = new AwtScrollPane(); { DWORD style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; jint scrollbarDisplayPolicy = env->GetIntField(target, scrollbarDisplayPolicyID); if (scrollbarDisplayPolicy == java_awt_ScrollPane_SCROLLBARS_ALWAYS) { style |= WS_HSCROLL | WS_VSCROLL; } DWORD exStyle = WS_EX_CLIENTEDGE; if (GetRTL()) { exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; } 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); c->CreateHWnd(env, L"", style, exStyle, x, y, width, height, awtParent->GetHWnd(), reinterpret_cast<HMENU>(static_cast<INT_PTR>( awtParent->CreateControlID())), ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), self); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return c; }
AwtCheckbox* AwtCheckbox::Create(jobject peer, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jstring label = NULL; jobject target = NULL; AwtCheckbox *checkbox = NULL; try { if (env->EnsureLocalCapacity(2) < 0) { return NULL; } AwtComponent* awtParent; JNI_CHECK_NULL_GOTO(parent, "null parent", done); awtParent = (AwtComponent*)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); checkbox = new AwtCheckbox(); { DWORD style = WS_CHILD | WS_CLIPSIBLINGS | BS_OWNERDRAW; LPCWSTR defaultLabelStr = L""; LPCWSTR labelStr = defaultLabelStr; DWORD exStyle = 0; if (GetRTL()) { exStyle |= WS_EX_RIGHT; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; } label = (jstring)env->GetObjectField(target, AwtCheckbox::labelID); if (label != NULL) { labelStr = JNU_GetStringPlatformChars(env, label, 0); } if (labelStr != 0) { 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); checkbox->CreateHWnd(env, labelStr, style, exStyle, x, y, width, height, awtParent->GetHWnd(), reinterpret_cast<HMENU>(static_cast<INT_PTR>( awtParent->CreateControlID())), ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_BTNFACE), peer); if (labelStr != defaultLabelStr) { JNU_ReleaseStringPlatformChars(env, label, labelStr); } } else { throw std::bad_alloc(); } } } catch (...) { env->DeleteLocalRef(label); env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(label); env->DeleteLocalRef(target); return checkbox; }
/* Create a new AwtList object and window. */ AwtList* AwtList::Create(jobject peer, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtList* c = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } PDATA pData; AwtCanvas* awtParent; JNI_CHECK_PEER_GOTO(parent, done); awtParent = (AwtCanvas*)pData; JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); /* target is Hjava_awt_List * */ target = env->GetObjectField(peer, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); c = new AwtList(); { /* * NOTE: WS_CLIPCHILDREN is excluded so that repaint requests * from Java will pass through the wrap to the native listbox. */ DWORD wrapStyle = WS_CHILD | WS_CLIPSIBLINGS; DWORD wrapExStyle = 0; DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | LBS_OWNERDRAWFIXED; DWORD exStyle = WS_EX_CLIENTEDGE; /* * NOTE: WS_VISIBLE is always set for the listbox. Listbox * visibility is controlled by toggling the wrap's WS_VISIBLE bit. */ style |= WS_VISIBLE; if (GetRTL()) { exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; } 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); c->CreateHWnd(env, L"", style, exStyle, x, y, width, height, awtParent->GetHWnd(), NULL, ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), peer ); /* suppress inheriting awtParent's color. */ c->m_backgroundColorSet = TRUE; c->UpdateBackground(env, target); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return c; }
/* Create a new AwtTextField object and window. */ AwtTextField* AwtTextField::Create(jobject peer, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtTextField* c = NULL; try { PDATA pData; AwtCanvas* awtParent; JNI_CHECK_PEER_GOTO(parent, done); awtParent = (AwtCanvas*)pData; JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); target = env->GetObjectField(peer, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); c = new AwtTextField(); { DWORD style = WS_CHILD | WS_CLIPSIBLINGS | ES_LEFT | ES_AUTOHSCROLL | (IS_WIN4X ? 0 : WS_BORDER); DWORD exStyle = IS_WIN4X ? WS_EX_CLIENTEDGE : 0; if (GetRTL()) { exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; } 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); c->CreateHWnd(env, L"", style, exStyle, x, y, width, height, awtParent->GetHWnd(), reinterpret_cast<HMENU>(static_cast<INT_PTR>( awtParent->CreateControlID())), ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), peer); c->m_backgroundColorSet = TRUE; /* suppress inheriting parent's color. */ c->UpdateBackground(env, target); c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELPARAM(1, 1)); /* * Fix for BugTraq Id 4260109. * Set the text limit to the maximum. */ c->SendMessage(EM_SETLIMITTEXT); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return c; }
/* * Create a new AwtCanvas object and window. */ AwtCanvas* AwtCanvas::Create(jobject self, jobject hParent) { TRY; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtCanvas *canvas = NULL; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } AwtComponent* parent; JNI_CHECK_NULL_GOTO(hParent, "null hParent", done); parent = (AwtComponent*)JNI_GET_PDATA(hParent); JNI_CHECK_NULL_GOTO(parent, "null parent", done); target = env->GetObjectField(self, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); canvas = new AwtCanvas(); { 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); canvas->CreateHWnd(env, L"", WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, x, y, width, height, parent->GetHWnd(), NULL, ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), self); // Set the pixel format of the HWND if a GraphicsConfiguration // was provided to the Canvas constructor. jclass canvasClass = env->FindClass("java/awt/Canvas"); if ( env->IsInstanceOf( target, canvasClass ) ) { // Get GraphicsConfig from our target jobject graphicsConfig = env->GetObjectField(target, AwtComponent::graphicsConfigID); if (graphicsConfig != NULL) { jclass win32cls = env->FindClass("sun/awt/Win32GraphicsConfig"); DASSERT (win32cls != NULL); if ( env->IsInstanceOf( graphicsConfig, win32cls ) ) { // Get the visual ID member from our GC jint visual = env->GetIntField(graphicsConfig, AwtWin32GraphicsConfig::win32GCVisualID); if (visual > 0) { HDC hdc = ::GetDC(canvas->m_hwnd); // Set our pixel format PIXELFORMATDESCRIPTOR pfd; BOOL ret = ::SetPixelFormat(hdc, (int)visual, &pfd); ::ReleaseDC(canvas->m_hwnd, hdc); //Since a GraphicsConfiguration was specified, we should //throw an exception if the PixelFormat couldn't be set. if (ret == FALSE) { DASSERT(!safe_ExceptionOccurred(env)); jclass excCls = env->FindClass( "java/lang/RuntimeException"); DASSERT(excCls); env->ExceptionClear(); env->ThrowNew(excCls, "\nUnable to set Pixel format on Canvas"); env->DeleteLocalRef(target); return canvas; } } } } } } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return canvas; CATCH_BAD_ALLOC_RET(0); }