136 jobject window; 137 jintArray data; 138 HBITMAP hBitmap; 139 jint width, height; 140 }; 141 // Struct for _RequestWindowFocus() method 142 struct RequestWindowFocusStruct { 143 jobject component; 144 jboolean isMouseEventCause; 145 }; 146 // struct for _RepositionSecurityWarning() method 147 struct RepositionSecurityWarningStruct { 148 jobject window; 149 }; 150 151 struct SetFullScreenExclusiveModeStateStruct { 152 jobject window; 153 jboolean isFSEMState; 154 }; 155 156 157 /************************************************************************ 158 * AwtWindow fields 159 */ 160 161 jfieldID AwtWindow::warningStringID; 162 jfieldID AwtWindow::locationByPlatformID; 163 jfieldID AwtWindow::autoRequestFocusID; 164 jfieldID AwtWindow::securityWarningWidthID; 165 jfieldID AwtWindow::securityWarningHeightID; 166 167 jfieldID AwtWindow::sysXID; 168 jfieldID AwtWindow::sysYID; 169 jfieldID AwtWindow::sysWID; 170 jfieldID AwtWindow::sysHID; 171 jfieldID AwtWindow::windowTypeID; 172 173 jmethodID AwtWindow::getWarningStringMID; 174 jmethodID AwtWindow::calculateSecurityWarningPositionMID; 175 jmethodID AwtWindow::windowTypeNameMID; 1736 CheckIfOnNewScreen(); 1737 } 1738 1739 /* Update the java AWT target component's fields directly */ 1740 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 1741 if (env->EnsureLocalCapacity(1) < 0) { 1742 return mrConsume; 1743 } 1744 jobject peer = GetPeer(env); 1745 jobject target = env->GetObjectField(peer, AwtObject::targetID); 1746 1747 RECT rect; 1748 ::GetWindowRect(GetHWnd(), &rect); 1749 1750 (env)->SetIntField(target, AwtComponent::xID, ScaleDownX(rect.left)); 1751 (env)->SetIntField(target, AwtComponent::yID, ScaleDownY(rect.top)); 1752 (env)->SetIntField(peer, AwtWindow::sysXID, ScaleDownX(rect.left)); 1753 (env)->SetIntField(peer, AwtWindow::sysYID, ScaleDownY(rect.top)); 1754 SendComponentEvent(java_awt_event_ComponentEvent_COMPONENT_MOVED); 1755 1756 env->DeleteLocalRef(target); 1757 return AwtComponent::WmMove(x, y); 1758 } 1759 1760 MsgRouting AwtWindow::WmGetMinMaxInfo(LPMINMAXINFO lpmmi) 1761 { 1762 MsgRouting r = AwtCanvas::WmGetMinMaxInfo(lpmmi); 1763 if ((m_minSize.x == 0) && (m_minSize.y == 0)) { 1764 return r; 1765 } 1766 lpmmi->ptMinTrackSize.x = m_minSize.x; 1767 lpmmi->ptMinTrackSize.y = m_minSize.y; 1768 return mrConsume; 1769 } 1770 1771 MsgRouting AwtWindow::WmSizing() 1772 { 1773 if (!AwtToolkit::GetInstance().IsDynamicLayoutActive()) { 1774 return mrDoDefault; 1775 } 2036 HMONITOR hmon; 2037 int scrnNum; 2038 2039 hmon = ::MonitorFromWindow(GetHWnd(), MONITOR_DEFAULTTOPRIMARY); 2040 DASSERT(hmon != NULL); 2041 2042 scrnNum = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(hmon); 2043 DASSERT(scrnNum > -1); 2044 2045 return scrnNum; 2046 } 2047 2048 /* Check to see if we've been moved onto another screen. 2049 * If so, update internal data, surfaces, etc. 2050 */ 2051 2052 void AwtWindow::CheckIfOnNewScreen() { 2053 int curScrn = GetScreenImOn(); 2054 2055 if (curScrn != m_screenNum) { // we've been moved 2056 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 2057 2058 jclass peerCls = env->GetObjectClass(m_peerObject); 2059 DASSERT(peerCls); 2060 CHECK_NULL(peerCls); 2061 2062 jmethodID draggedID = env->GetMethodID(peerCls, "draggedToNewScreen", 2063 "()V"); 2064 DASSERT(draggedID); 2065 if (draggedID == NULL) { 2066 env->DeleteLocalRef(peerCls); 2067 return; 2068 } 2069 2070 env->CallVoidMethod(m_peerObject, draggedID); 2071 m_screenNum = curScrn; 2072 2073 env->DeleteLocalRef(peerCls); 2074 } 2075 } 2076 2077 BOOL AwtWindow::IsFocusableWindow() { 2078 /* 2079 * For Window/Frame/Dialog to accept focus it should: 2080 * - be focusable; 2081 * - be not blocked by any modal blocker. 2082 */ 2083 BOOL focusable = m_isFocusableWindow && !::IsWindow(AwtWindow::GetModalBlocker(GetHWnd())); 2084 AwtFrame *owner = GetOwningFrameOrDialog(); // NULL for Frame and Dialog 2085 2086 if (owner != NULL) { 2087 /* 2088 * Also for Window (not Frame/Dialog) to accept focus: 2089 * - its decorated parent should accept focus; 2090 */ 2091 focusable = focusable && owner->IsFocusableWindow(); 2092 } 2093 return focusable; 2094 } 2095 2096 void AwtWindow::SetModalBlocker(HWND window, HWND blocker) { 3085 } 3086 3087 void AwtWindow::_GetNativeWindowSize(void* param) { 3088 3089 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 3090 3091 SizeStruct *ss = (SizeStruct *)param; 3092 jobject self = ss->window; 3093 AwtWindow *window = NULL; 3094 PDATA pData; 3095 JNI_CHECK_PEER_RETURN(self); 3096 window = (AwtWindow *)pData; 3097 3098 RECT rc; 3099 ::GetWindowRect(window->GetHWnd(), &rc); 3100 ss->w = rc.right - rc.left; 3101 ss->h = rc.bottom - rc.top; 3102 3103 env->DeleteGlobalRef(self); 3104 } 3105 extern "C" int getSystemMetricValue(int msgType); 3106 extern "C" { 3107 3108 /* 3109 * Class: java_awt_Window 3110 * Method: initIDs 3111 * Signature: ()V 3112 */ 3113 JNIEXPORT void JNICALL 3114 Java_java_awt_Window_initIDs(JNIEnv *env, jclass cls) 3115 { 3116 TRY; 3117 3118 CHECK_NULL(AwtWindow::warningStringID = 3119 env->GetFieldID(cls, "warningString", "Ljava/lang/String;")); 3120 CHECK_NULL(AwtWindow::locationByPlatformID = 3121 env->GetFieldID(cls, "locationByPlatform", "Z")); 3122 CHECK_NULL(AwtWindow::securityWarningWidthID = 3123 env->GetFieldID(cls, "securityWarningWidth", "I")); 3124 CHECK_NULL(AwtWindow::securityWarningHeightID = 3783 * Method: repositionSecurityWarning 3784 * Signature: ()V 3785 */ 3786 JNIEXPORT void JNICALL 3787 Java_sun_awt_windows_WWindowPeer_repositionSecurityWarning(JNIEnv *env, 3788 jobject self) 3789 { 3790 TRY; 3791 3792 RepositionSecurityWarningStruct *rsws = 3793 new RepositionSecurityWarningStruct; 3794 rsws->window = env->NewGlobalRef(self); 3795 3796 AwtToolkit::GetInstance().InvokeFunction( 3797 AwtWindow::_RepositionSecurityWarning, rsws); 3798 // global refs and mds are deleted in _RepositionSecurityWarning 3799 3800 CATCH_BAD_ALLOC; 3801 } 3802 3803 } /* extern "C" */ | 136 jobject window; 137 jintArray data; 138 HBITMAP hBitmap; 139 jint width, height; 140 }; 141 // Struct for _RequestWindowFocus() method 142 struct RequestWindowFocusStruct { 143 jobject component; 144 jboolean isMouseEventCause; 145 }; 146 // struct for _RepositionSecurityWarning() method 147 struct RepositionSecurityWarningStruct { 148 jobject window; 149 }; 150 151 struct SetFullScreenExclusiveModeStateStruct { 152 jobject window; 153 jboolean isFSEMState; 154 }; 155 156 // struct for _WindowDPIChange() method 157 struct ScaleStruct { 158 jobject window; 159 jfloat prevScaleX; 160 jfloat prevScaleY; 161 jfloat scaleX; 162 jfloat scaleY; 163 }; 164 165 /************************************************************************ 166 * AwtWindow fields 167 */ 168 169 jfieldID AwtWindow::warningStringID; 170 jfieldID AwtWindow::locationByPlatformID; 171 jfieldID AwtWindow::autoRequestFocusID; 172 jfieldID AwtWindow::securityWarningWidthID; 173 jfieldID AwtWindow::securityWarningHeightID; 174 175 jfieldID AwtWindow::sysXID; 176 jfieldID AwtWindow::sysYID; 177 jfieldID AwtWindow::sysWID; 178 jfieldID AwtWindow::sysHID; 179 jfieldID AwtWindow::windowTypeID; 180 181 jmethodID AwtWindow::getWarningStringMID; 182 jmethodID AwtWindow::calculateSecurityWarningPositionMID; 183 jmethodID AwtWindow::windowTypeNameMID; 1744 CheckIfOnNewScreen(); 1745 } 1746 1747 /* Update the java AWT target component's fields directly */ 1748 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 1749 if (env->EnsureLocalCapacity(1) < 0) { 1750 return mrConsume; 1751 } 1752 jobject peer = GetPeer(env); 1753 jobject target = env->GetObjectField(peer, AwtObject::targetID); 1754 1755 RECT rect; 1756 ::GetWindowRect(GetHWnd(), &rect); 1757 1758 (env)->SetIntField(target, AwtComponent::xID, ScaleDownX(rect.left)); 1759 (env)->SetIntField(target, AwtComponent::yID, ScaleDownY(rect.top)); 1760 (env)->SetIntField(peer, AwtWindow::sysXID, ScaleDownX(rect.left)); 1761 (env)->SetIntField(peer, AwtWindow::sysYID, ScaleDownY(rect.top)); 1762 SendComponentEvent(java_awt_event_ComponentEvent_COMPONENT_MOVED); 1763 1764 prevX = rect.left; 1765 prevY = rect.top; 1766 1767 env->DeleteLocalRef(target); 1768 return AwtComponent::WmMove(x, y); 1769 } 1770 1771 MsgRouting AwtWindow::WmGetMinMaxInfo(LPMINMAXINFO lpmmi) 1772 { 1773 MsgRouting r = AwtCanvas::WmGetMinMaxInfo(lpmmi); 1774 if ((m_minSize.x == 0) && (m_minSize.y == 0)) { 1775 return r; 1776 } 1777 lpmmi->ptMinTrackSize.x = m_minSize.x; 1778 lpmmi->ptMinTrackSize.y = m_minSize.y; 1779 return mrConsume; 1780 } 1781 1782 MsgRouting AwtWindow::WmSizing() 1783 { 1784 if (!AwtToolkit::GetInstance().IsDynamicLayoutActive()) { 1785 return mrDoDefault; 1786 } 2047 HMONITOR hmon; 2048 int scrnNum; 2049 2050 hmon = ::MonitorFromWindow(GetHWnd(), MONITOR_DEFAULTTOPRIMARY); 2051 DASSERT(hmon != NULL); 2052 2053 scrnNum = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(hmon); 2054 DASSERT(scrnNum > -1); 2055 2056 return scrnNum; 2057 } 2058 2059 /* Check to see if we've been moved onto another screen. 2060 * If so, update internal data, surfaces, etc. 2061 */ 2062 2063 void AwtWindow::CheckIfOnNewScreen() { 2064 int curScrn = GetScreenImOn(); 2065 2066 if (curScrn != m_screenNum) { // we've been moved 2067 int prevScrn = m_screenNum; 2068 2069 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 2070 2071 jclass peerCls = env->GetObjectClass(m_peerObject); 2072 DASSERT(peerCls); 2073 CHECK_NULL(peerCls); 2074 2075 jmethodID draggedID = env->GetMethodID(peerCls, "draggedToNewScreen", 2076 "()V"); 2077 DASSERT(draggedID); 2078 if (draggedID == NULL) { 2079 env->DeleteLocalRef(peerCls); 2080 return; 2081 } 2082 2083 env->CallVoidMethod(m_peerObject, draggedID); 2084 2085 m_screenNum = curScrn; 2086 WindowDPIChange(prevScrn, curScrn); 2087 2088 env->DeleteLocalRef(peerCls); 2089 } 2090 } 2091 2092 int Disposition(int x1, int x2, int x) { 2093 return x < x1 ? -1 : (x > x2 ? 1 : 0); 2094 } 2095 2096 void AwtWindow::WindowDPIChange(int prevScreen, int screen) { 2097 Devices::InstanceAccess devices; 2098 AwtWin32GraphicsDevice* prevDevice = devices->GetDevice(prevScreen); 2099 AwtWin32GraphicsDevice* device = devices->GetDevice(screen); 2100 2101 if (prevDevice && device) { 2102 RECT prevBounds; 2103 RECT bounds; 2104 2105 if (MonitorBounds(prevDevice->GetMonitor(), &prevBounds) 2106 && MonitorBounds(device->GetMonitor(), &bounds)) { 2107 int x; 2108 int y; 2109 int dx; 2110 int dy; 2111 RECT rect; 2112 2113 ::GetWindowRect(GetHWnd(), &rect); 2114 x = rect.left; 2115 y = rect.top; 2116 dx = x - prevX; 2117 dy = y - prevY; 2118 2119 if (dx != 0 || dy != 0) { 2120 int w = rect.right - rect.left; 2121 int h = rect.bottom - rect.top; 2122 int dispX = Disposition(prevBounds.left, prevBounds.right, 2123 (bounds.left + bounds.right) / 2); 2124 int dispY = Disposition(prevBounds.top, prevBounds.bottom, 2125 (bounds.top + bounds.bottom) / 2); 2126 2127 w = w * device->GetScaleX() / prevDevice->GetScaleX(); 2128 h = h * device->GetScaleY() / prevDevice->GetScaleY(); 2129 2130 prevX = x; 2131 prevY = y; 2132 2133 if (dx != 0 && dispX != 0) { 2134 x = dispX > 0 ? bounds.left : bounds.right - w; 2135 y = min(y, bounds.top); 2136 ReshapeNoScale(x, y, w, h); 2137 } else if (dy != 0 && dispY != 0) { 2138 x = max(x, bounds.left); 2139 y = dispY > 0 ? bounds.top : bounds.bottom - h; 2140 ReshapeNoScale(x, y, w, h); 2141 } 2142 } 2143 } 2144 } 2145 } 2146 2147 void AwtWindow::WindowDPIChange(float prevScaleX, float prevScaleY, float scaleX, float scaleY) { 2148 int w; 2149 int h; 2150 RECT rect; 2151 2152 ::GetWindowRect(GetHWnd(), &rect); 2153 2154 w = (rect.right - rect.left) * scaleX / prevScaleX; 2155 h = (rect.bottom - rect.top) * scaleY / prevScaleY; 2156 ReshapeNoScale(rect.left, rect.top, w, h); 2157 } 2158 2159 BOOL AwtWindow::IsFocusableWindow() { 2160 /* 2161 * For Window/Frame/Dialog to accept focus it should: 2162 * - be focusable; 2163 * - be not blocked by any modal blocker. 2164 */ 2165 BOOL focusable = m_isFocusableWindow && !::IsWindow(AwtWindow::GetModalBlocker(GetHWnd())); 2166 AwtFrame *owner = GetOwningFrameOrDialog(); // NULL for Frame and Dialog 2167 2168 if (owner != NULL) { 2169 /* 2170 * Also for Window (not Frame/Dialog) to accept focus: 2171 * - its decorated parent should accept focus; 2172 */ 2173 focusable = focusable && owner->IsFocusableWindow(); 2174 } 2175 return focusable; 2176 } 2177 2178 void AwtWindow::SetModalBlocker(HWND window, HWND blocker) { 3167 } 3168 3169 void AwtWindow::_GetNativeWindowSize(void* param) { 3170 3171 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 3172 3173 SizeStruct *ss = (SizeStruct *)param; 3174 jobject self = ss->window; 3175 AwtWindow *window = NULL; 3176 PDATA pData; 3177 JNI_CHECK_PEER_RETURN(self); 3178 window = (AwtWindow *)pData; 3179 3180 RECT rc; 3181 ::GetWindowRect(window->GetHWnd(), &rc); 3182 ss->w = rc.right - rc.left; 3183 ss->h = rc.bottom - rc.top; 3184 3185 env->DeleteGlobalRef(self); 3186 } 3187 3188 void AwtWindow::_WindowDPIChange(void* param) 3189 { 3190 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 3191 3192 ScaleStruct *ss = (ScaleStruct *)param; 3193 jobject self = ss->window; 3194 jfloat prevScaleX = ss->prevScaleX; 3195 jfloat prevScaleY = ss->prevScaleY; 3196 jfloat scaleX = ss->scaleX; 3197 jfloat scaleY = ss->scaleY; 3198 3199 PDATA pData; 3200 JNI_CHECK_PEER_GOTO(self, ret); 3201 AwtWindow *window = (AwtWindow *)pData; 3202 3203 window->WindowDPIChange(prevScaleX, prevScaleY, scaleX, scaleY); 3204 3205 ret: 3206 env->DeleteGlobalRef(self); 3207 delete ss; 3208 } 3209 3210 3211 extern "C" int getSystemMetricValue(int msgType); 3212 extern "C" { 3213 3214 /* 3215 * Class: java_awt_Window 3216 * Method: initIDs 3217 * Signature: ()V 3218 */ 3219 JNIEXPORT void JNICALL 3220 Java_java_awt_Window_initIDs(JNIEnv *env, jclass cls) 3221 { 3222 TRY; 3223 3224 CHECK_NULL(AwtWindow::warningStringID = 3225 env->GetFieldID(cls, "warningString", "Ljava/lang/String;")); 3226 CHECK_NULL(AwtWindow::locationByPlatformID = 3227 env->GetFieldID(cls, "locationByPlatform", "Z")); 3228 CHECK_NULL(AwtWindow::securityWarningWidthID = 3229 env->GetFieldID(cls, "securityWarningWidth", "I")); 3230 CHECK_NULL(AwtWindow::securityWarningHeightID = 3889 * Method: repositionSecurityWarning 3890 * Signature: ()V 3891 */ 3892 JNIEXPORT void JNICALL 3893 Java_sun_awt_windows_WWindowPeer_repositionSecurityWarning(JNIEnv *env, 3894 jobject self) 3895 { 3896 TRY; 3897 3898 RepositionSecurityWarningStruct *rsws = 3899 new RepositionSecurityWarningStruct; 3900 rsws->window = env->NewGlobalRef(self); 3901 3902 AwtToolkit::GetInstance().InvokeFunction( 3903 AwtWindow::_RepositionSecurityWarning, rsws); 3904 // global refs and mds are deleted in _RepositionSecurityWarning 3905 3906 CATCH_BAD_ALLOC; 3907 } 3908 3909 /* 3910 * Class: sun_awt_windows_WWindowPeer 3911 * Method: windowDPIChange 3912 * Signature: (FFFF)V 3913 */ 3914 JNIEXPORT void JNICALL 3915 Java_sun_awt_windows_WWindowPeer_windowDPIChange(JNIEnv *env, jobject self, 3916 jfloat prevScaleX, jfloat prevScaleY, jfloat scaleX, jfloat scaleY) 3917 { 3918 TRY; 3919 3920 ScaleStruct *ss = new ScaleStruct; 3921 ss->window = env->NewGlobalRef(self); 3922 ss->prevScaleX = prevScaleX; 3923 ss->prevScaleY = prevScaleY; 3924 ss->scaleX = scaleX; 3925 ss->scaleY = scaleY; 3926 3927 AwtToolkit::GetInstance().SyncCall(AwtWindow::_WindowDPIChange, ss); 3928 // global refs and mds are deleted in _SetMinSize 3929 3930 CATCH_BAD_ALLOC; 3931 } 3932 } /* extern "C" */ |