< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Window.cpp

Print this page
rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX


 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     jint prevScreen;
 160     jfloat prevScaleX;
 161     jfloat prevScaleY;
 162     jint screen;
 163     jfloat scaleX;
 164     jfloat scaleY;
 165 };
 166 
 167 struct OverrideHandle {
 168     jobject frame;
 169     HWND handle;
 170 };
 171 
 172 /************************************************************************
 173  * AwtWindow fields
 174  */
 175 
 176 jfieldID AwtWindow::warningStringID;
 177 jfieldID AwtWindow::locationByPlatformID;
 178 jfieldID AwtWindow::autoRequestFocusID;
 179 jfieldID AwtWindow::securityWarningWidthID;
 180 jfieldID AwtWindow::securityWarningHeightID;
 181 
 182 jfieldID AwtWindow::sysXID;
 183 jfieldID AwtWindow::sysYID;
 184 jfieldID AwtWindow::sysWID;
 185 jfieldID AwtWindow::sysHID;
 186 jfieldID AwtWindow::windowTypeID;
 187 
 188 jmethodID AwtWindow::getWarningStringMID;
 189 jmethodID AwtWindow::calculateSecurityWarningPositionMID;
 190 jmethodID AwtWindow::windowTypeNameMID;
 191 
 192 int AwtWindow::ms_instanceCounter = 0;
 193 HHOOK AwtWindow::ms_hCBTFilter;
 194 AwtWindow * AwtWindow::m_grabbedWindow = NULL;
 195 BOOL AwtWindow::sm_resizing = FALSE;
 196 UINT AwtWindow::untrustedWindowsCounter = 0;
 197 
 198 /************************************************************************
 199  * AwtWindow class methods
 200  */
 201 
 202 AwtWindow::AwtWindow() {
 203     m_sizePt.x = m_sizePt.y = 0;
 204     m_owningFrameDialog = NULL;
 205     m_isResizable = FALSE;//Default value is replaced after construction


1110         window = new AwtWindow();
1111 
1112         {
1113             if (JNU_IsInstanceOfByName(env, target, "javax/swing/Popup$HeavyWeightWindow") > 0) {
1114                 window->m_isRetainingHierarchyZOrder = TRUE;
1115             }
1116             if (env->ExceptionCheck()) goto done;
1117             DWORD style = WS_CLIPCHILDREN | WS_POPUP;
1118             DWORD exStyle = WS_EX_NOACTIVATE;
1119             if (GetRTL()) {
1120                 exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR;
1121                 if (GetRTLReadingOrder())
1122                     exStyle |= WS_EX_RTLREADING;
1123             }
1124             if (awtParent != NULL) {
1125                 window->InitOwner(awtParent);
1126             } else {
1127                 // specify WS_EX_TOOLWINDOW to remove parentless windows from taskbar
1128                 exStyle |= WS_EX_TOOLWINDOW;
1129             }





1130             window->CreateHWnd(env, L"",
1131                                style, exStyle,
1132                                0, 0, 0, 0,
1133                                (awtParent != NULL) ? awtParent->GetHWnd() : NULL,
1134                                NULL,
1135                                ::GetSysColor(COLOR_WINDOWTEXT),
1136                                ::GetSysColor(COLOR_WINDOW),
1137                                self);
1138 
1139             jint x = env->GetIntField(target, AwtComponent::xID);
1140             jint y = env->GetIntField(target, AwtComponent::yID);
1141             jint width = env->GetIntField(target, AwtComponent::widthID);
1142             jint height = env->GetIntField(target, AwtComponent::heightID);
1143 
1144             /*
1145              * Initialize icon as inherited from parent if it exists
1146              */
1147             if (parent != NULL) {
1148                 window->m_hIcon = awtParent->GetHIcon();
1149                 window->m_hIconSm = awtParent->GetHIconSm();
1150                 window->m_iconInherited = TRUE;
1151             }
1152             window->DoUpdateIcon();
1153 
1154 
1155             /*
1156              * Reshape here instead of during create, so that a WM_NCCALCSIZE
1157              * is sent.
1158              */
1159             window->Reshape(x, y, width, height);
1160         }
1161     } catch (...) {
1162         env->DeleteLocalRef(target);
1163         throw;
1164     }
1165 
1166 done:
1167     env->DeleteLocalRef(target);
1168     return window;
1169 }
1170 
1171 BOOL AwtWindow::IsOneOfOwnersOf(AwtWindow * wnd) {
1172     while (wnd != NULL) {
1173         if (wnd == this || wnd->GetOwningFrameOrDialog() == this) return TRUE;
1174         wnd = (AwtWindow*)GetComponent(::GetWindow(wnd->GetHWnd(), GW_OWNER));
1175     }
1176     return FALSE;
1177 }
1178 
1179 void AwtWindow::InitOwner(AwtWindow *owner)


1197 
1198 void AwtWindow::moveToDefaultLocation() {
1199     HWND boggy = ::CreateWindow(GetClassName(), L"BOGGY", WS_OVERLAPPED, CW_USEDEFAULT, 0 ,0, 0,
1200         NULL, NULL, NULL, NULL);
1201     RECT defLoc;
1202 
1203     // Fixed 6477497: Windows drawn off-screen on Win98, even when java.awt.Window.locationByPlatform is set
1204     //    Win9x does not position a window until the window is shown.
1205     //    The behavior is slightly opposite to the WinNT (and up), where
1206     //    Windows will position the window upon creation of the window.
1207     //    That's why we have to manually set the left & top values of
1208     //    the defLoc to 0 if the GetWindowRect function returns FALSE.
1209     BOOL result = ::GetWindowRect(boggy, &defLoc);
1210     if (!result) {
1211         defLoc.left = defLoc.top = 0;
1212     }
1213     VERIFY(::DestroyWindow(boggy));
1214     VERIFY(::SetWindowPos(GetHWnd(), NULL, defLoc.left, defLoc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER));
1215 }
1216 









































1217 void AwtWindow::Show()
1218 {
1219     m_visible = true;
1220     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1221     BOOL  done = false;
1222     HWND hWnd = GetHWnd();
1223 
1224     if (env->EnsureLocalCapacity(2) < 0) {
1225         return;
1226     }
1227     jobject target = GetTarget(env);
1228     INT nCmdShow;
1229 
1230     AwtFrame* owningFrame = GetOwningFrameOrDialog();
1231     if (IsFocusableWindow() && IsAutoRequestFocus() && owningFrame != NULL &&
1232         ::GetForegroundWindow() == owningFrame->GetHWnd())
1233     {
1234         nCmdShow = SW_SHOW;
1235     } else {
1236         nCmdShow = SW_SHOWNA;


1746     HWND hwndOwner = ::GetParent(hwndSelf);
1747 
1748     if (!show && IsSimpleWindow() && hwndSelf == AwtComponent::GetFocusedWindow() &&
1749         hwndOwner != NULL && ::IsWindowVisible(hwndOwner))
1750     {
1751         AwtFrame *owner = (AwtFrame*)AwtComponent::GetComponent(hwndOwner);
1752         if (owner != NULL) {
1753             owner->AwtSetActiveWindow();
1754         }
1755     }
1756 
1757     //Fixed 4842599: REGRESSION: JPopupMenu not Hidden Properly After Iconified and Deiconified
1758     if (show && (status == SW_PARENTOPENING)) {
1759         if (!IsVisible()) {
1760             return mrConsume;
1761         }
1762     }
1763     return AwtCanvas::WmShowWindow(show, status);
1764 }
1765 









1766 /*
1767  * Override AwtComponent's move handling to first update the
1768  * java AWT target's position fields directly, since Windows
1769  * and below can be resized from outside of java (by user)
1770  */
1771 MsgRouting AwtWindow::WmMove(int x, int y)
1772 {
1773     if ( ::IsIconic(GetHWnd()) ) {
1774     // fixes 4065534 (robi.khan@eng)
1775     // if a window is iconified we don't want to update
1776     // it's target's position since minimized Win32 windows
1777     // move to -32000, -32000 for whatever reason
1778     // NOTE: See also AwtWindow::Reshape
1779         return mrDoDefault;
1780     }
1781 
1782     if (m_screenNum == -1) {
1783     // Set initial value
1784         m_screenNum = GetScreenImOn();
1785     }
1786     else {
1787         CheckIfOnNewScreen();
1788     }
1789 
1790     /* Update the java AWT target component's fields directly */
1791     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1792     if (env->EnsureLocalCapacity(1) < 0) {
1793         return mrConsume;
1794     }
1795     jobject peer = GetPeer(env);
1796     jobject target = env->GetObjectField(peer, AwtObject::targetID);
1797 
1798     RECT rect;
1799     ::GetWindowRect(GetHWnd(), &rect);
1800 
1801     (env)->SetIntField(target, AwtComponent::xID, ScaleDownX(rect.left));
1802     (env)->SetIntField(target, AwtComponent::yID, ScaleDownY(rect.top));
1803     (env)->SetIntField(peer, AwtWindow::sysXID, ScaleDownX(rect.left));
1804     (env)->SetIntField(peer, AwtWindow::sysYID, ScaleDownY(rect.top));
1805     SendComponentEvent(java_awt_event_ComponentEvent_COMPONENT_MOVED);
1806 
1807     env->DeleteLocalRef(target);
1808     return AwtComponent::WmMove(x, y);
1809 }
1810 
1811 MsgRouting AwtWindow::WmGetMinMaxInfo(LPMINMAXINFO lpmmi)
1812 {
1813     MsgRouting r = AwtCanvas::WmGetMinMaxInfo(lpmmi);
1814     if ((m_minSize.x == 0) && (m_minSize.y == 0)) {
1815         return r;
1816     }
1817     lpmmi->ptMinTrackSize.x = m_minSize.x;
1818     lpmmi->ptMinTrackSize.y = m_minSize.y;
1819     return mrConsume;
1820 }
1821 
1822 MsgRouting AwtWindow::WmSizing()
1823 {
1824     if (!AwtToolkit::GetInstance().IsDynamicLayoutActive()) {


1829 
1830     SendComponentEvent(java_awt_event_ComponentEvent_COMPONENT_RESIZED);
1831 
1832     HWND thisHwnd = GetHWnd();
1833     if (thisHwnd == NULL) {
1834         return mrDoDefault;
1835     }
1836 
1837     // Call WComponentPeer::dynamicallyLayoutContainer()
1838     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1839     jobject peer = GetPeer(env);
1840     JNU_CallMethodByName(env, NULL, peer, "dynamicallyLayoutContainer", "()V");
1841     DASSERT(!safe_ExceptionOccurred(env));
1842 
1843     return mrDoDefault;
1844 }
1845 
1846 MsgRouting AwtWindow::WmEnterSizeMove()
1847 {
1848     m_winSizeMove = TRUE;









1849     return mrDoDefault;
1850 }
1851 
1852 MsgRouting AwtWindow::WmExitSizeMove()
1853 {
1854     m_winSizeMove = FALSE;
1855     CheckWindowDPIChange();
1856     return mrDoDefault;
1857 }
1858 
1859 /*
1860  * Override AwtComponent's size handling to first update the
1861  * java AWT target's dimension fields directly, since Windows
1862  * and below can be resized from outside of java (by user)
1863  */
1864 MsgRouting AwtWindow::WmSize(UINT type, int w, int h)
1865 {
1866     currentWmSizeState = type;
1867 
1868     if (type == SIZE_MINIMIZED) {
1869         UpdateSecurityWarningVisibility();
1870         return mrDoDefault;
1871     }


1872 
1873     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1874     if (env->EnsureLocalCapacity(1) < 0)
1875         return mrDoDefault;
1876     jobject target = GetTarget(env);
1877     // fix 4167248 : ensure the insets are up-to-date before using
1878     BOOL insetsChanged = UpdateInsets(NULL);
1879     int newWidth = w + m_insets.left + m_insets.right;
1880     int newHeight = h + m_insets.top + m_insets.bottom;
1881 
1882     (env)->SetIntField(target, AwtComponent::widthID, ScaleDownX(newWidth));
1883     (env)->SetIntField(target, AwtComponent::heightID, ScaleDownY(newHeight));
1884 
1885     jobject peer = GetPeer(env);
1886     (env)->SetIntField(peer, AwtWindow::sysWID, ScaleDownX(newWidth));
1887     (env)->SetIntField(peer, AwtWindow::sysHID, ScaleDownY(newHeight));
1888 
1889     if (!AwtWindow::IsResizing()) {
1890         WindowResized();
1891     }
1892 
1893     env->DeleteLocalRef(target);
1894     return AwtComponent::WmSize(type, w, h);
1895 }
1896 
1897 MsgRouting AwtWindow::WmPaint(HDC)
1898 {
1899     PaintUpdateRgn(&m_insets);
1900     return mrConsume;
1901 }
1902 
1903 MsgRouting AwtWindow::WmSettingChange(UINT wFlag, LPCTSTR pszSection)
1904 {
1905     if (wFlag == SPI_SETNONCLIENTMETRICS) {
1906     // user changed window metrics in
1907     // Control Panel->Display->Appearance


1949     // actions to be launched from sysmenu is implemented by ignoring WM_SYSCOMMAND
1950     if (::IsWindow(GetModalBlocker(GetHWnd()))) {
1951         retVal = HTCLIENT;
1952     } else {
1953         retVal = DefWindowProc(WM_NCHITTEST, 0, MAKELPARAM(x, y));
1954     }
1955     return mrConsume;
1956 }
1957 
1958 MsgRouting AwtWindow::WmGetIcon(WPARAM iconType, LRESULT& retValue)
1959 {
1960     return mrDoDefault;
1961 }
1962 
1963 LRESULT AwtWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1964 {
1965     MsgRouting mr = mrDoDefault;
1966     LRESULT retValue = 0L;
1967 
1968     switch(message) {





1969         case WM_GETICON:
1970             mr = WmGetIcon(wParam, retValue);
1971             break;
1972         case WM_SYSCOMMAND:
1973             //Fixed 6355340: Contents of frame are not layed out properly on maximize
1974             if ((wParam & 0xFFF0) == SC_SIZE) {
1975                 AwtWindow::sm_resizing = TRUE;
1976                 mr = WmSysCommand(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1977                 if (mr != mrConsume) {
1978                     // Perform size-move loop here
1979                     AwtWindow::DefWindowProc(message, wParam, lParam);
1980                 }
1981                 AwtWindow::sm_resizing = FALSE;
1982                 if (!AwtToolkit::GetInstance().IsDynamicLayoutActive()) {
1983                     WindowResized();
1984                 } else {
1985                     /*
1986                      * 8016356: check whether window snapping occurred after
1987                      * resizing, i.e. GetWindowRect() returns the real
1988                      * (snapped) window rectangle, e.g. (179, 0)-(483, 1040),


2092 // window border (updates insets) and redraws border to match
2093 //
2094 void AwtWindow::RedrawNonClient()
2095 {
2096     ::SetWindowPos(GetHWnd(), (HWND) NULL, 0, 0, 0, 0, SwpFrameChangeFlags|SWP_ASYNCWINDOWPOS);
2097 }
2098 
2099 int AwtWindow::GetScreenImOn() {
2100     HMONITOR hmon;
2101     int scrnNum;
2102 
2103     hmon = ::MonitorFromWindow(GetHWnd(), MONITOR_DEFAULTTOPRIMARY);
2104     DASSERT(hmon != NULL);
2105 
2106     scrnNum = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(hmon);
2107     DASSERT(scrnNum > -1);
2108 
2109     return scrnNum;
2110 }
2111 
2112 /* Check to see if we've been moved onto another screen.

2113  * If so, update internal data, surfaces, etc.
2114  */
2115 
2116 void AwtWindow::CheckIfOnNewScreen() {
2117     int curScrn = GetScreenImOn();
2118 
2119     if (curScrn != m_screenNum) {  // we've been moved














2120         JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
2121 
2122         jclass peerCls = env->GetObjectClass(m_peerObject);
2123         DASSERT(peerCls);
2124         CHECK_NULL(peerCls);
2125 
2126         jmethodID draggedID = env->GetMethodID(peerCls, "draggedToNewScreen",
2127                                                "()V");
2128         DASSERT(draggedID);
2129         if (draggedID == NULL) {
2130             env->DeleteLocalRef(peerCls);
2131             return;
2132         }
2133 
2134         env->CallVoidMethod(m_peerObject, draggedID);
2135         m_screenNum = curScrn;
2136 
2137         env->DeleteLocalRef(peerCls);
2138     }
2139 }
2140 




2141 void AwtWindow::CheckWindowDPIChange() {
2142 
2143     if (prevScaleRec.screen != -1 ) {
2144         float prevScaleX = prevScaleRec.scaleX;
2145         float prevScaleY = prevScaleRec.scaleY;
2146 
2147         if (prevScaleX >= 1 && prevScaleY >= 1) {
2148             Devices::InstanceAccess devices;
2149             AwtWin32GraphicsDevice* device = devices->GetDevice(m_screenNum);
2150             if (device) {
2151                 float scaleX = device->GetScaleX();
2152                 float scaleY = device->GetScaleY();
2153                 if (prevScaleX != scaleX || prevScaleY != scaleY) {
2154                     WindowDPIChange(prevScaleRec.screen, prevScaleX, prevScaleY,
2155                                     m_screenNum, scaleX, scaleY);
2156                 }
2157             }
2158         }
2159         prevScaleRec.screen = -1;
2160     }
2161 }
2162 
2163 void AwtWindow::WindowDPIChange(int prevScreen,
2164                                 float prevScaleX, float prevScaleY,
2165                                 int screen, float scaleX,
2166                                 float scaleY)
2167 {
2168     int x;
2169     int y;
2170     int w;
2171     int h;
2172     RECT rect;
2173 
2174     if (prevScaleX == scaleX && prevScaleY == scaleY) {
2175         return;
2176     }
2177 
2178     ::GetWindowRect(GetHWnd(), &rect);
2179     x = rect.left;
2180     y = rect.top;
2181     w = (rect.right - rect.left) * scaleX / prevScaleX;
2182     h = (rect.bottom - rect.top) * scaleY / prevScaleY;
2183 
2184     if (prevScreen != screen) {
2185         Devices::InstanceAccess devices;
2186         AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
2187         if (device) {
2188             RECT bounds;
2189             if (MonitorBounds(device->GetMonitor(), &bounds)) {
2190                 x = x < bounds.left ? bounds.left : x;
2191                 y = y < bounds.top ? bounds.top : y;
2192 
2193                 x = (x + w > bounds.right) ? bounds.right - w : x;
2194                 y = (y + h > bounds.bottom) ? bounds.bottom - h : y;
2195             }

2196         }
2197     }
2198 
2199     ReshapeNoScale(x, y, w, h);


2200 }
2201 
2202 BOOL AwtWindow::IsFocusableWindow() {
2203     /*
2204      * For Window/Frame/Dialog to accept focus it should:
2205      * - be focusable;
2206      * - be not blocked by any modal blocker.
2207      */
2208     BOOL focusable = m_isFocusableWindow && !::IsWindow(AwtWindow::GetModalBlocker(GetHWnd()));
2209     AwtFrame *owner = GetOwningFrameOrDialog(); // NULL for Frame and Dialog
2210 
2211     if (owner != NULL) {
2212         /*
2213          * Also for Window (not Frame/Dialog) to accept focus:
2214          * - its decorated parent should accept focus;
2215          */
2216         focusable = focusable && owner->IsFocusableWindow();
2217     }
2218     return focusable;
2219 }


2554 
2555     PDATA pData;
2556     JNI_CHECK_PEER_GOTO(self, ret);
2557     p = (AwtFrame *)pData;
2558     if (::IsWindow(p->GetHWnd()))
2559     {
2560         jobject target = env->GetObjectField(self, AwtObject::targetID);
2561         if (target != NULL)
2562         {
2563             // enforce tresholds before sending the event
2564             // Fix for 4459064 : do not enforce thresholds for embedded frames
2565             if (!p->IsEmbeddedFrame())
2566             {
2567                 jobject peer = p->GetPeer(env);
2568                 int minWidth = p->ScaleDownX(::GetSystemMetrics(SM_CXMIN));
2569                 int minHeight = p->ScaleDownY(::GetSystemMetrics(SM_CYMIN));
2570                 if (w < minWidth)
2571                 {
2572                     env->SetIntField(target, AwtComponent::widthID,
2573                         w = minWidth);
2574                     env->SetIntField(peer, AwtWindow::sysWID,
2575                         w);
2576                 }
2577                 if (h < minHeight)
2578                 {
2579                     env->SetIntField(target, AwtComponent::heightID,
2580                         h = minHeight);
2581                     env->SetIntField(peer, AwtWindow::sysHID,
2582                         h);
2583                 }
2584             }
2585             env->DeleteLocalRef(target);
2586 
2587             RECT *r = new RECT;
2588             ::SetRect(r, x, y, x + w, y + h);
2589             p->SendMessage(WM_AWT_RESHAPE_COMPONENT, 0, (LPARAM)r);
2590             // r is deleted in message handler
2591 
2592             // After the input method window shown, the dimension & position may not
2593             // be valid until this method is called. So we need to adjust the
2594             // IME candidate window position for the same reason as commented on
2595             // awt_Frame.cpp Show() method.
2596             if (p->isInputMethodWindow() && ::IsWindowVisible(p->GetHWnd())) {
2597               p->AdjustCandidateWindowPos();
2598             }
2599         }
2600         else
2601         {
2602             JNU_ThrowNullPointerException(env, "null target");


3229 
3230 void AwtWindow::_GetNativeWindowSize(void* param) {
3231 
3232     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
3233 
3234     SizeStruct *ss = (SizeStruct *)param;
3235     jobject self = ss->window;
3236     AwtWindow *window = NULL;
3237     PDATA pData;
3238     JNI_CHECK_PEER_RETURN(self);
3239     window = (AwtWindow *)pData;
3240 
3241     RECT rc;
3242     ::GetWindowRect(window->GetHWnd(), &rc);
3243     ss->w = rc.right - rc.left;
3244     ss->h = rc.bottom - rc.top;
3245 
3246     env->DeleteGlobalRef(self);
3247 }
3248 
3249 void AwtWindow::_WindowDPIChange(void* param)
3250 {
3251     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
3252 
3253     ScaleStruct *ss = (ScaleStruct *)param;
3254     jobject self = ss->window;
3255     jint prevScreen = ss->prevScreen;
3256     jfloat prevScaleX = ss->prevScaleX;
3257     jfloat prevScaleY = ss->prevScaleY;
3258     jint screen = ss->screen;
3259     jfloat scaleX = ss->scaleX;
3260     jfloat scaleY = ss->scaleY;
3261 
3262     PDATA pData;
3263     JNI_CHECK_PEER_GOTO(self, ret);
3264     AwtWindow *window = (AwtWindow *)pData;
3265 
3266     if (window->m_winSizeMove) {
3267         if (window->prevScaleRec.screen == -1) {
3268             window->prevScaleRec.screen = prevScreen;
3269             window->prevScaleRec.scaleX = prevScaleX;
3270             window->prevScaleRec.scaleY = prevScaleY;
3271         }
3272     }
3273     else {
3274         window->WindowDPIChange(prevScreen, prevScaleX, prevScaleY,
3275                                 screen, scaleX, scaleY);
3276     }
3277 
3278 ret:
3279     env->DeleteGlobalRef(self);
3280     delete ss;
3281 }
3282 
3283 extern "C" int getSystemMetricValue(int msgType);
3284 extern "C" {
3285 
3286 /*
3287  * Class:     java_awt_Window
3288  * Method:    initIDs
3289  * Signature: ()V
3290  */
3291 JNIEXPORT void JNICALL
3292 Java_java_awt_Window_initIDs(JNIEnv *env, jclass cls)
3293 {
3294     TRY;
3295 
3296     CHECK_NULL(AwtWindow::warningStringID =
3297         env->GetFieldID(cls, "warningString", "Ljava/lang/String;"));
3298     CHECK_NULL(AwtWindow::locationByPlatformID =
3299         env->GetFieldID(cls, "locationByPlatform", "Z"));
3300     CHECK_NULL(AwtWindow::securityWarningWidthID =
3301         env->GetFieldID(cls, "securityWarningWidth", "I"));


3319 
3320 } /* extern "C" */
3321 
3322 
3323 /************************************************************************
3324  * WindowPeer native methods
3325  */
3326 
3327 extern "C" {
3328 
3329 /*
3330  * Class:     sun_awt_windows_WWindowPeer
3331  * Method:    initIDs
3332  * Signature: ()V
3333  */
3334 JNIEXPORT void JNICALL
3335 Java_sun_awt_windows_WWindowPeer_initIDs(JNIEnv *env, jclass cls)
3336 {
3337     TRY;
3338 
3339     CHECK_NULL(AwtWindow::sysXID = env->GetFieldID(cls, "sysX", "I"));
3340     CHECK_NULL(AwtWindow::sysYID = env->GetFieldID(cls, "sysY", "I"));
3341     CHECK_NULL(AwtWindow::sysWID = env->GetFieldID(cls, "sysW", "I"));
3342     CHECK_NULL(AwtWindow::sysHID = env->GetFieldID(cls, "sysH", "I"));
3343 
3344     AwtWindow::windowTypeID = env->GetFieldID(cls, "windowType",
3345             "Ljava/awt/Window$Type;");
3346 
3347     CATCH_BAD_ALLOC;
3348 }
3349 
3350 /*
3351  * Class:     sun_awt_windows_WWindowPeer
3352  * Method:    toFront
3353  * Signature: ()V
3354  */
3355 JNIEXPORT void JNICALL
3356 Java_sun_awt_windows_WWindowPeer__1toFront(JNIEnv *env, jobject self)
3357 {
3358     TRY;
3359 
3360     AwtToolkit::GetInstance().SyncCall(AwtWindow::_ToFront,
3361         env->NewGlobalRef(self));
3362     // global ref is deleted in _ToFront()
3363 


3959  * Signature: ()V
3960  */
3961 JNIEXPORT void JNICALL
3962 Java_sun_awt_windows_WWindowPeer_repositionSecurityWarning(JNIEnv *env,
3963         jobject self)
3964 {
3965     TRY;
3966 
3967     RepositionSecurityWarningStruct *rsws =
3968         new RepositionSecurityWarningStruct;
3969     rsws->window = env->NewGlobalRef(self);
3970 
3971     AwtToolkit::GetInstance().InvokeFunction(
3972             AwtWindow::_RepositionSecurityWarning, rsws);
3973     // global refs and mds are deleted in _RepositionSecurityWarning
3974 
3975     CATCH_BAD_ALLOC;
3976 }
3977 
3978 /*
3979 * Class:     sun_awt_windows_WWindowPeer
3980 * Method:    windowDPIChange
3981 * Signature: (IFFIFF)V
3982 */
3983 JNIEXPORT void JNICALL
3984 Java_sun_awt_windows_WWindowPeer_windowDPIChange(JNIEnv *env, jobject self,
3985     jint prevScreen, jfloat prevScaleX, jfloat prevScaleY,
3986     jint screen, jfloat scaleX, jfloat scaleY)
3987 {
3988     TRY;
3989 
3990     ScaleStruct *ss = new ScaleStruct;
3991     ss->window = env->NewGlobalRef(self);
3992     ss->prevScreen = prevScreen;
3993     ss->prevScaleX = prevScaleX;
3994     ss->prevScaleY = prevScaleY;
3995     ss->screen = screen;
3996     ss->scaleX = scaleX;
3997     ss->scaleY = scaleY;
3998 
3999     AwtToolkit::GetInstance().InvokeFunction(AwtWindow::_WindowDPIChange, ss);
4000     // global refs and ss are deleted in _WindowDPIChange
4001 
4002     CATCH_BAD_ALLOC;
4003 }
4004 
4005 /*
4006  * Class:     sun_awt_windows_WLightweightFramePeer
4007  * Method:    overrideNativeHandle
4008  * Signature: (J)V
4009  */
4010 JNIEXPORT void JNICALL Java_sun_awt_windows_WLightweightFramePeer_overrideNativeHandle
4011   (JNIEnv *env, jobject self, jlong hwnd)
4012 {
4013     TRY;
4014 
4015     OverrideHandle *oh = new OverrideHandle;
4016     oh->frame = env->NewGlobalRef(self);
4017     oh->handle = (HWND) hwnd;
4018 
4019     AwtToolkit::GetInstance().SyncCall(AwtFrame::_OverrideHandle, oh);
4020     // global ref and oh are deleted in _OverrideHandle()
4021 
4022     CATCH_BAD_ALLOC;
4023 }
4024 
4025 } /* 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 OverrideHandle {
 157     jobject frame;
 158     HWND handle;
 159 };
 160 
 161 /************************************************************************
 162  * AwtWindow fields
 163  */
 164 
 165 jfieldID AwtWindow::warningStringID;
 166 jfieldID AwtWindow::locationByPlatformID;
 167 jfieldID AwtWindow::autoRequestFocusID;
 168 jfieldID AwtWindow::securityWarningWidthID;
 169 jfieldID AwtWindow::securityWarningHeightID;
 170 




 171 jfieldID AwtWindow::windowTypeID;
 172 
 173 jmethodID AwtWindow::getWarningStringMID;
 174 jmethodID AwtWindow::calculateSecurityWarningPositionMID;
 175 jmethodID AwtWindow::windowTypeNameMID;
 176 
 177 int AwtWindow::ms_instanceCounter = 0;
 178 HHOOK AwtWindow::ms_hCBTFilter;
 179 AwtWindow * AwtWindow::m_grabbedWindow = NULL;
 180 BOOL AwtWindow::sm_resizing = FALSE;
 181 UINT AwtWindow::untrustedWindowsCounter = 0;
 182 
 183 /************************************************************************
 184  * AwtWindow class methods
 185  */
 186 
 187 AwtWindow::AwtWindow() {
 188     m_sizePt.x = m_sizePt.y = 0;
 189     m_owningFrameDialog = NULL;
 190     m_isResizable = FALSE;//Default value is replaced after construction


1095         window = new AwtWindow();
1096 
1097         {
1098             if (JNU_IsInstanceOfByName(env, target, "javax/swing/Popup$HeavyWeightWindow") > 0) {
1099                 window->m_isRetainingHierarchyZOrder = TRUE;
1100             }
1101             if (env->ExceptionCheck()) goto done;
1102             DWORD style = WS_CLIPCHILDREN | WS_POPUP;
1103             DWORD exStyle = WS_EX_NOACTIVATE;
1104             if (GetRTL()) {
1105                 exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR;
1106                 if (GetRTLReadingOrder())
1107                     exStyle |= WS_EX_RTLREADING;
1108             }
1109             if (awtParent != NULL) {
1110                 window->InitOwner(awtParent);
1111             } else {
1112                 // specify WS_EX_TOOLWINDOW to remove parentless windows from taskbar
1113                 exStyle |= WS_EX_TOOLWINDOW;
1114             }
1115             jint x = env->GetIntField(target, AwtComponent::xID);

1116             jint y = env->GetIntField(target, AwtComponent::yID);

1117             jint width = env->GetIntField(target, AwtComponent::widthID);

1118             jint height = env->GetIntField(target, AwtComponent::heightID);

1119 

1120             window->CreateHWnd(env, L"",
1121                                style, exStyle,
1122                                x, y, width, height,

1123                                (awtParent != NULL) ? awtParent->GetHWnd() : NULL,
1124                                NULL,
1125                                ::GetSysColor(COLOR_WINDOWTEXT),
1126                                ::GetSysColor(COLOR_WINDOW),
1127                                self);






1128             /*
1129              * Initialize icon as inherited from parent if it exists
1130              */
1131             if (parent != NULL) {
1132                 window->m_hIcon = awtParent->GetHIcon();
1133                 window->m_hIconSm = awtParent->GetHIconSm();
1134                 window->m_iconInherited = TRUE;
1135             }
1136             window->DoUpdateIcon();
1137             window->RecalcNonClient();







1138         }
1139     } catch (...) {
1140         env->DeleteLocalRef(target);
1141         throw;
1142     }
1143 
1144 done:
1145     env->DeleteLocalRef(target);
1146     return window;
1147 }
1148 
1149 BOOL AwtWindow::IsOneOfOwnersOf(AwtWindow * wnd) {
1150     while (wnd != NULL) {
1151         if (wnd == this || wnd->GetOwningFrameOrDialog() == this) return TRUE;
1152         wnd = (AwtWindow*)GetComponent(::GetWindow(wnd->GetHWnd(), GW_OWNER));
1153     }
1154     return FALSE;
1155 }
1156 
1157 void AwtWindow::InitOwner(AwtWindow *owner)


1175 
1176 void AwtWindow::moveToDefaultLocation() {
1177     HWND boggy = ::CreateWindow(GetClassName(), L"BOGGY", WS_OVERLAPPED, CW_USEDEFAULT, 0 ,0, 0,
1178         NULL, NULL, NULL, NULL);
1179     RECT defLoc;
1180 
1181     // Fixed 6477497: Windows drawn off-screen on Win98, even when java.awt.Window.locationByPlatform is set
1182     //    Win9x does not position a window until the window is shown.
1183     //    The behavior is slightly opposite to the WinNT (and up), where
1184     //    Windows will position the window upon creation of the window.
1185     //    That's why we have to manually set the left & top values of
1186     //    the defLoc to 0 if the GetWindowRect function returns FALSE.
1187     BOOL result = ::GetWindowRect(boggy, &defLoc);
1188     if (!result) {
1189         defLoc.left = defLoc.top = 0;
1190     }
1191     VERIFY(::DestroyWindow(boggy));
1192     VERIFY(::SetWindowPos(GetHWnd(), NULL, defLoc.left, defLoc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER));
1193 }
1194 
1195 /**

1196  * Override AwtComponent::Reshape() to handle absolute screen coordinates used

1197  * by the top-level windows.

1198  */

1199 void AwtWindow::Reshape(int x, int y, int w, int h) {

1200     if (IsEmbeddedFrame()) {

1201         // Not the "real" top level window

1202         return AwtComponent::Reshape(x, y, w, h);

1203     }

1204     // Yes, use x,y in user's space to find the nearest monitor in device space.

1205     POINT pt = {x + w / 2, y + h / 2};

1206     Devices::InstanceAccess devices;

1207     HMONITOR monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

1208     int screen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(monitor);

1209     AwtWin32GraphicsDevice *device = devices->GetDevice(screen);

1210     // Try set the correct size and jump to the correct location, even if it is

1211     // on the different monitor. Note that for the "size" we use the current

1212     // monitor, so the WM_DPICHANGED will adjust it for the "target" monitor.

1213     ReshapeNoScale(device->ScaleUpAbsX(x), device->ScaleUpAbsY(y),

1214                    ScaleUpX(w), ScaleUpY(h));

1215     // The window manager may tweak the size for different reasons, so try

1216     // to make sure our window has the correct size in the user's space.

1217     // NOOP if the size was changed already or changing is in progress.

1218     RECT rc;

1219     ::GetWindowRect(GetHWnd(), &rc);

1220     ReshapeNoScale(rc.left, rc.top, ScaleUpX(w), ScaleUpY(h));

1221     // the window manager may ignore our "SetWindowPos" request, in this,

1222     // case the WmMove/WmSize will not come and we need to manually resync

1223     // the "java.awt.Window" locations, because "java.awt.Window" already

1224     // uses location ignored by the window manager.

1225     ::GetWindowRect(GetHWnd(), &rc);

1226     if (x != ScaleDownAbsX(rc.left) || y != ScaleDownAbsY(rc.top)) {

1227         WmMove(rc.left, rc.top);

1228     }

1229     int userW = ScaleDownX(rc.right - rc.left);

1230     int userH = ScaleDownY(rc.bottom - rc.top);

1231     if (w != userW || h != userH) {

1232         WmSize(SIZENORMAL, rc.right - rc.left, rc.bottom - rc.top);

1233     }

1234 }

1235 

1236 void AwtWindow::Show()
1237 {
1238     m_visible = true;
1239     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1240     BOOL  done = false;
1241     HWND hWnd = GetHWnd();
1242 
1243     if (env->EnsureLocalCapacity(2) < 0) {
1244         return;
1245     }
1246     jobject target = GetTarget(env);
1247     INT nCmdShow;
1248 
1249     AwtFrame* owningFrame = GetOwningFrameOrDialog();
1250     if (IsFocusableWindow() && IsAutoRequestFocus() && owningFrame != NULL &&
1251         ::GetForegroundWindow() == owningFrame->GetHWnd())
1252     {
1253         nCmdShow = SW_SHOW;
1254     } else {
1255         nCmdShow = SW_SHOWNA;


1765     HWND hwndOwner = ::GetParent(hwndSelf);
1766 
1767     if (!show && IsSimpleWindow() && hwndSelf == AwtComponent::GetFocusedWindow() &&
1768         hwndOwner != NULL && ::IsWindowVisible(hwndOwner))
1769     {
1770         AwtFrame *owner = (AwtFrame*)AwtComponent::GetComponent(hwndOwner);
1771         if (owner != NULL) {
1772             owner->AwtSetActiveWindow();
1773         }
1774     }
1775 
1776     //Fixed 4842599: REGRESSION: JPopupMenu not Hidden Properly After Iconified and Deiconified
1777     if (show && (status == SW_PARENTOPENING)) {
1778         if (!IsVisible()) {
1779             return mrConsume;
1780         }
1781     }
1782     return AwtCanvas::WmShowWindow(show, status);
1783 }
1784 
1785 void AwtWindow::WmDPIChanged(const LPARAM &lParam) {

1786     // need to update the scales now, otherwise the ReshapeNoScale() will

1787     // calculate the bounds wrongly

1788     AwtWin32GraphicsDevice::ResetAllDesktopScales();

1789     RECT *r = (RECT *) lParam;

1790     ReshapeNoScale(r->left, r->top, r->right - r->left, r->bottom - r->top);

1791     CheckIfOnNewScreen(true);

1792 }

1793 

1794 /*
1795  * Override AwtComponent's move handling to first update the
1796  * java AWT target's position fields directly, since Windows
1797  * and below can be resized from outside of java (by user)
1798  */
1799 MsgRouting AwtWindow::WmMove(int x, int y)
1800 {
1801     if ( ::IsIconic(GetHWnd()) ) {
1802     // fixes 4065534 (robi.khan@eng)
1803     // if a window is iconified we don't want to update
1804     // it's target's position since minimized Win32 windows
1805     // move to -32000, -32000 for whatever reason
1806     // NOTE: See also AwtWindow::Reshape
1807         return mrDoDefault;
1808     }
1809     // Check for the new screen and update the java peer

1810     CheckIfOnNewScreen(false); // postpone if different DPI







1811 
1812     /* Update the java AWT target component's fields directly */
1813     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1814     if (env->EnsureLocalCapacity(1) < 0) {
1815         return mrConsume;
1816     }
1817     jobject target = GetTarget(env);


1818 
1819     RECT rect;
1820     ::GetWindowRect(GetHWnd(), &rect);
1821 
1822     (env)->SetIntField(target, AwtComponent::xID, ScaleDownAbsX(rect.left));

1823     (env)->SetIntField(target, AwtComponent::yID, ScaleDownAbsY(rect.top));



1824     SendComponentEvent(java_awt_event_ComponentEvent_COMPONENT_MOVED);
1825 
1826     env->DeleteLocalRef(target);
1827     return AwtComponent::WmMove(x, y);
1828 }
1829 
1830 MsgRouting AwtWindow::WmGetMinMaxInfo(LPMINMAXINFO lpmmi)
1831 {
1832     MsgRouting r = AwtCanvas::WmGetMinMaxInfo(lpmmi);
1833     if ((m_minSize.x == 0) && (m_minSize.y == 0)) {
1834         return r;
1835     }
1836     lpmmi->ptMinTrackSize.x = m_minSize.x;
1837     lpmmi->ptMinTrackSize.y = m_minSize.y;
1838     return mrConsume;
1839 }
1840 
1841 MsgRouting AwtWindow::WmSizing()
1842 {
1843     if (!AwtToolkit::GetInstance().IsDynamicLayoutActive()) {


1848 
1849     SendComponentEvent(java_awt_event_ComponentEvent_COMPONENT_RESIZED);
1850 
1851     HWND thisHwnd = GetHWnd();
1852     if (thisHwnd == NULL) {
1853         return mrDoDefault;
1854     }
1855 
1856     // Call WComponentPeer::dynamicallyLayoutContainer()
1857     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1858     jobject peer = GetPeer(env);
1859     JNU_CallMethodByName(env, NULL, peer, "dynamicallyLayoutContainer", "()V");
1860     DASSERT(!safe_ExceptionOccurred(env));
1861 
1862     return mrDoDefault;
1863 }
1864 
1865 MsgRouting AwtWindow::WmEnterSizeMove()
1866 {
1867     m_winSizeMove = TRUE;
1868     // Below is a workaround, see CheckWindowDPIChange

1869     Devices::InstanceAccess devices;

1870     AwtWin32GraphicsDevice* device = devices->GetDevice(m_screenNum);

1871     if (device) {

1872         prevScaleRec.screen = m_screenNum;

1873         prevScaleRec.scaleX = device->GetScaleX();

1874         prevScaleRec.scaleY = device->GetScaleY();

1875     }

1876     // Above is a workaround

1877     return mrDoDefault;
1878 }
1879 
1880 MsgRouting AwtWindow::WmExitSizeMove()
1881 {
1882     m_winSizeMove = FALSE;
1883     CheckWindowDPIChange(); // workaround

1884     return mrDoDefault;
1885 }
1886 
1887 /*
1888  * Override AwtComponent's size handling to first update the
1889  * java AWT target's dimension fields directly, since Windows
1890  * and below can be resized from outside of java (by user)
1891  */
1892 MsgRouting AwtWindow::WmSize(UINT type, int w, int h)
1893 {
1894     currentWmSizeState = type;
1895 
1896     if (type == SIZE_MINIMIZED) {
1897         UpdateSecurityWarningVisibility();
1898         return mrDoDefault;
1899     }
1900     // Check for the new screen and update the java peer

1901     CheckIfOnNewScreen(false); // postpone if different DPI

1902 
1903     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
1904     if (env->EnsureLocalCapacity(1) < 0)
1905         return mrDoDefault;
1906     jobject target = GetTarget(env);
1907     // fix 4167248 : ensure the insets are up-to-date before using
1908     BOOL insetsChanged = UpdateInsets(NULL);
1909     (env)->SetIntField(target, AwtComponent::widthID, ScaleDownX(w));

1910     (env)->SetIntField(target, AwtComponent::heightID, ScaleDownY(h));








1911 
1912     if (!AwtWindow::IsResizing()) {
1913         WindowResized();
1914     }
1915 
1916     env->DeleteLocalRef(target);
1917     return AwtComponent::WmSize(type, w, h);
1918 }
1919 
1920 MsgRouting AwtWindow::WmPaint(HDC)
1921 {
1922     PaintUpdateRgn(&m_insets);
1923     return mrConsume;
1924 }
1925 
1926 MsgRouting AwtWindow::WmSettingChange(UINT wFlag, LPCTSTR pszSection)
1927 {
1928     if (wFlag == SPI_SETNONCLIENTMETRICS) {
1929     // user changed window metrics in
1930     // Control Panel->Display->Appearance


1972     // actions to be launched from sysmenu is implemented by ignoring WM_SYSCOMMAND
1973     if (::IsWindow(GetModalBlocker(GetHWnd()))) {
1974         retVal = HTCLIENT;
1975     } else {
1976         retVal = DefWindowProc(WM_NCHITTEST, 0, MAKELPARAM(x, y));
1977     }
1978     return mrConsume;
1979 }
1980 
1981 MsgRouting AwtWindow::WmGetIcon(WPARAM iconType, LRESULT& retValue)
1982 {
1983     return mrDoDefault;
1984 }
1985 
1986 LRESULT AwtWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1987 {
1988     MsgRouting mr = mrDoDefault;
1989     LRESULT retValue = 0L;
1990 
1991     switch(message) {
1992         case WM_DPICHANGED: {

1993             WmDPIChanged(lParam);

1994             mr = mrConsume;

1995             break;

1996         }

1997         case WM_GETICON:
1998             mr = WmGetIcon(wParam, retValue);
1999             break;
2000         case WM_SYSCOMMAND:
2001             //Fixed 6355340: Contents of frame are not layed out properly on maximize
2002             if ((wParam & 0xFFF0) == SC_SIZE) {
2003                 AwtWindow::sm_resizing = TRUE;
2004                 mr = WmSysCommand(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
2005                 if (mr != mrConsume) {
2006                     // Perform size-move loop here
2007                     AwtWindow::DefWindowProc(message, wParam, lParam);
2008                 }
2009                 AwtWindow::sm_resizing = FALSE;
2010                 if (!AwtToolkit::GetInstance().IsDynamicLayoutActive()) {
2011                     WindowResized();
2012                 } else {
2013                     /*
2014                      * 8016356: check whether window snapping occurred after
2015                      * resizing, i.e. GetWindowRect() returns the real
2016                      * (snapped) window rectangle, e.g. (179, 0)-(483, 1040),


2120 // window border (updates insets) and redraws border to match
2121 //
2122 void AwtWindow::RedrawNonClient()
2123 {
2124     ::SetWindowPos(GetHWnd(), (HWND) NULL, 0, 0, 0, 0, SwpFrameChangeFlags|SWP_ASYNCWINDOWPOS);
2125 }
2126 
2127 int AwtWindow::GetScreenImOn() {
2128     HMONITOR hmon;
2129     int scrnNum;
2130 
2131     hmon = ::MonitorFromWindow(GetHWnd(), MONITOR_DEFAULTTOPRIMARY);
2132     DASSERT(hmon != NULL);
2133 
2134     scrnNum = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(hmon);
2135     DASSERT(scrnNum > -1);
2136 
2137     return scrnNum;
2138 }
2139 
2140 /*

2141  * Check to see if we've been moved onto another screen.

2142  * If so, update internal data, surfaces, etc.
2143  */
2144 void AwtWindow::CheckIfOnNewScreen(BOOL force) {


2145     int curScrn = GetScreenImOn();
2146 
2147     if (curScrn != m_screenNum) {  // we've been moved
2148         // if moved from one monitor to another with different DPI, we should

2149         // update the m_screenNum only if the size was updated as well in the

2150         // WM_DPICHANGED.

2151         Devices::InstanceAccess devices;

2152         AwtWin32GraphicsDevice* oldDevice = devices->GetDevice(m_screenNum);

2153         AwtWin32GraphicsDevice* newDevice = devices->GetDevice(curScrn);

2154         if (!force && m_winSizeMove && oldDevice && newDevice) {

2155             if (oldDevice->GetScaleX() != newDevice->GetScaleX()

2156                     || oldDevice->GetScaleY() != newDevice->GetScaleY()) {

2157                 // scales are different, wait for WM_DPICHANGED

2158                 return;

2159             }

2160         }

2161 

2162         JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
2163 
2164         jclass peerCls = env->GetObjectClass(m_peerObject);
2165         DASSERT(peerCls);
2166         CHECK_NULL(peerCls);
2167 
2168         jmethodID draggedID = env->GetMethodID(peerCls, "draggedToNewScreen",
2169                                                "()V");
2170         DASSERT(draggedID);
2171         if (draggedID == NULL) {
2172             env->DeleteLocalRef(peerCls);
2173             return;
2174         }
2175 
2176         env->CallVoidMethod(m_peerObject, draggedID);
2177         m_screenNum = curScrn;
2178 
2179         env->DeleteLocalRef(peerCls);
2180     }
2181 }
2182 
2183 // The shared code is not ready to the top-level window which crosses a few

2184 // monitors with different DPI. Popup windows will start to use wrong screen,

2185 // will be placed in the wrong place and will be use wrong size, see 8249164

2186 // So we will "JUMP TO" the new screen.

2187 void AwtWindow::CheckWindowDPIChange() {
2188     if (prevScaleRec.screen != -1 && prevScaleRec.screen != m_screenNum) {






2189         Devices::InstanceAccess devices;
2190         AwtWin32GraphicsDevice *device = devices->GetDevice(m_screenNum);

2191         if (device) {
2192             if (prevScaleRec.scaleX != device->GetScaleX()

2193                     || prevScaleRec.scaleY != device->GetScaleY()) {




















2194                 RECT rect;





2195                 ::GetWindowRect(GetHWnd(), &rect);
2196                 int x = rect.left;

2197                 int y = rect.top;

2198                 int w = rect.right - rect.left;

2199                 int h = rect.bottom - rect.top;






2200                 RECT bounds;
2201                 if (MonitorBounds(device->GetMonitor(), &bounds)) {
2202                     x = x < bounds.left ? bounds.left : x;
2203                     y = y < bounds.top ? bounds.top : y;

2204                     x = (x + w > bounds.right) ? bounds.right - w : x;
2205                     y = (y + h > bounds.bottom) ? bounds.bottom - h : y;
2206                 }
2207                 ReshapeNoScale(x, y, w, h);

2208             }
2209         }
2210         prevScaleRec.screen = -1;

2211         prevScaleRec.scaleX = -1.0f;

2212         prevScaleRec.scaleY = -1.0f;

2213     }

2214 }
2215 
2216 BOOL AwtWindow::IsFocusableWindow() {
2217     /*
2218      * For Window/Frame/Dialog to accept focus it should:
2219      * - be focusable;
2220      * - be not blocked by any modal blocker.
2221      */
2222     BOOL focusable = m_isFocusableWindow && !::IsWindow(AwtWindow::GetModalBlocker(GetHWnd()));
2223     AwtFrame *owner = GetOwningFrameOrDialog(); // NULL for Frame and Dialog
2224 
2225     if (owner != NULL) {
2226         /*
2227          * Also for Window (not Frame/Dialog) to accept focus:
2228          * - its decorated parent should accept focus;
2229          */
2230         focusable = focusable && owner->IsFocusableWindow();
2231     }
2232     return focusable;
2233 }


2568 
2569     PDATA pData;
2570     JNI_CHECK_PEER_GOTO(self, ret);
2571     p = (AwtFrame *)pData;
2572     if (::IsWindow(p->GetHWnd()))
2573     {
2574         jobject target = env->GetObjectField(self, AwtObject::targetID);
2575         if (target != NULL)
2576         {
2577             // enforce tresholds before sending the event
2578             // Fix for 4459064 : do not enforce thresholds for embedded frames
2579             if (!p->IsEmbeddedFrame())
2580             {
2581                 jobject peer = p->GetPeer(env);
2582                 int minWidth = p->ScaleDownX(::GetSystemMetrics(SM_CXMIN));
2583                 int minHeight = p->ScaleDownY(::GetSystemMetrics(SM_CYMIN));
2584                 if (w < minWidth)
2585                 {
2586                     env->SetIntField(target, AwtComponent::widthID,
2587                         w = minWidth);


2588                 }
2589                 if (h < minHeight)
2590                 {
2591                     env->SetIntField(target, AwtComponent::heightID,
2592                         h = minHeight);


2593                 }
2594             }
2595             env->DeleteLocalRef(target);
2596 
2597             RECT *r = new RECT;
2598             ::SetRect(r, x, y, x + w, y + h);
2599             p->SendMessage(WM_AWT_RESHAPE_COMPONENT, 0, (LPARAM)r);
2600             // r is deleted in message handler
2601 
2602             // After the input method window shown, the dimension & position may not
2603             // be valid until this method is called. So we need to adjust the
2604             // IME candidate window position for the same reason as commented on
2605             // awt_Frame.cpp Show() method.
2606             if (p->isInputMethodWindow() && ::IsWindowVisible(p->GetHWnd())) {
2607               p->AdjustCandidateWindowPos();
2608             }
2609         }
2610         else
2611         {
2612             JNU_ThrowNullPointerException(env, "null target");


3239 
3240 void AwtWindow::_GetNativeWindowSize(void* param) {
3241 
3242     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
3243 
3244     SizeStruct *ss = (SizeStruct *)param;
3245     jobject self = ss->window;
3246     AwtWindow *window = NULL;
3247     PDATA pData;
3248     JNI_CHECK_PEER_RETURN(self);
3249     window = (AwtWindow *)pData;
3250 
3251     RECT rc;
3252     ::GetWindowRect(window->GetHWnd(), &rc);
3253     ss->w = rc.right - rc.left;
3254     ss->h = rc.bottom - rc.top;
3255 
3256     env->DeleteGlobalRef(self);
3257 }
3258 

































3259 
3260 extern "C" int getSystemMetricValue(int msgType);
3261 extern "C" {
3262 
3263 /*
3264  * Class:     java_awt_Window
3265  * Method:    initIDs
3266  * Signature: ()V
3267  */
3268 JNIEXPORT void JNICALL
3269 Java_java_awt_Window_initIDs(JNIEnv *env, jclass cls)
3270 {
3271     TRY;
3272 
3273     CHECK_NULL(AwtWindow::warningStringID =
3274         env->GetFieldID(cls, "warningString", "Ljava/lang/String;"));
3275     CHECK_NULL(AwtWindow::locationByPlatformID =
3276         env->GetFieldID(cls, "locationByPlatform", "Z"));
3277     CHECK_NULL(AwtWindow::securityWarningWidthID =
3278         env->GetFieldID(cls, "securityWarningWidth", "I"));


3296 
3297 } /* extern "C" */
3298 
3299 
3300 /************************************************************************
3301  * WindowPeer native methods
3302  */
3303 
3304 extern "C" {
3305 
3306 /*
3307  * Class:     sun_awt_windows_WWindowPeer
3308  * Method:    initIDs
3309  * Signature: ()V
3310  */
3311 JNIEXPORT void JNICALL
3312 Java_sun_awt_windows_WWindowPeer_initIDs(JNIEnv *env, jclass cls)
3313 {
3314     TRY;
3315 





3316     AwtWindow::windowTypeID = env->GetFieldID(cls, "windowType",
3317             "Ljava/awt/Window$Type;");
3318 
3319     CATCH_BAD_ALLOC;
3320 }
3321 
3322 /*
3323  * Class:     sun_awt_windows_WWindowPeer
3324  * Method:    toFront
3325  * Signature: ()V
3326  */
3327 JNIEXPORT void JNICALL
3328 Java_sun_awt_windows_WWindowPeer__1toFront(JNIEnv *env, jobject self)
3329 {
3330     TRY;
3331 
3332     AwtToolkit::GetInstance().SyncCall(AwtWindow::_ToFront,
3333         env->NewGlobalRef(self));
3334     // global ref is deleted in _ToFront()
3335 


3931  * Signature: ()V
3932  */
3933 JNIEXPORT void JNICALL
3934 Java_sun_awt_windows_WWindowPeer_repositionSecurityWarning(JNIEnv *env,
3935         jobject self)
3936 {
3937     TRY;
3938 
3939     RepositionSecurityWarningStruct *rsws =
3940         new RepositionSecurityWarningStruct;
3941     rsws->window = env->NewGlobalRef(self);
3942 
3943     AwtToolkit::GetInstance().InvokeFunction(
3944             AwtWindow::_RepositionSecurityWarning, rsws);
3945     // global refs and mds are deleted in _RepositionSecurityWarning
3946 
3947     CATCH_BAD_ALLOC;
3948 }
3949 
3950 /*



























3951  * Class:     sun_awt_windows_WLightweightFramePeer
3952  * Method:    overrideNativeHandle
3953  * Signature: (J)V
3954  */
3955 JNIEXPORT void JNICALL Java_sun_awt_windows_WLightweightFramePeer_overrideNativeHandle
3956   (JNIEnv *env, jobject self, jlong hwnd)
3957 {
3958     TRY;
3959 
3960     OverrideHandle *oh = new OverrideHandle;
3961     oh->frame = env->NewGlobalRef(self);
3962     oh->handle = (HWND) hwnd;
3963 
3964     AwtToolkit::GetInstance().SyncCall(AwtFrame::_OverrideHandle, oh);
3965     // global ref and oh are deleted in _OverrideHandle()
3966 
3967     CATCH_BAD_ALLOC;
3968 }
3969 
3970 } /* extern "C" */
< prev index next >