JRE-612 [windows] icon in frame title is not dpi-aware

(cherry picked from commit dec04385177a2abb677add909d3b94f94c62a14e)

(cherry picked from commit 38466cbab0)
(cherry picked from commit 81662b38f5)
This commit is contained in:
Anton Tarasov
2017-12-25 16:18:38 +03:00
committed by jbrbot
parent 51c7f5ec2a
commit 5b13699620
7 changed files with 55 additions and 11 deletions

View File

@@ -128,6 +128,14 @@ class WFramePeer extends WWindowPeer implements FramePeer {
return bounds;
}
@Override
public void displayChanged() {
super.displayChanged();
updateIcon();
}
private native void updateIcon();
@Override
public boolean updateGraphicsData(GraphicsConfiguration gc) {
boolean result = super.updateGraphicsData(gc);

View File

@@ -403,7 +403,7 @@ HICON AwtDialog::GetEffectiveIcon(int iconType)
//Java cup icon is not loaded in window class for dialogs
//It needs to be set explicitly for resizable dialogs
//and ownerless dialogs
hIcon = (smallIcon) ? AwtToolkit::GetInstance().GetAwtIconSm() :
hIcon = (smallIcon) ? AwtToolkit::GetInstance().GetAwtIconSm(reinterpret_cast<void*>(this)) :
AwtToolkit::GetInstance().GetAwtIcon();
} else if ((hIcon != NULL) && IsIconInherited() && !isResizable) {
//Non-resizable dialogs without explicitly set icon

View File

@@ -1182,6 +1182,19 @@ MsgRouting AwtFrame::WmGetIcon(WPARAM iconType, LRESULT& retVal)
}
}
void _UpdateIcon(void* p) {
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
jobject self = reinterpret_cast<jobject>(p);
PDATA pData;
JNI_CHECK_PEER_GOTO(self, ret);
AwtFrame* frame = (AwtFrame*)pData;
frame->DoUpdateIcon();
ret:
env->DeleteGlobalRef(self);
}
void AwtFrame::DoUpdateIcon()
{
//Workaround windows bug:
@@ -1198,7 +1211,7 @@ HICON AwtFrame::GetEffectiveIcon(int iconType)
BOOL smallIcon = ((iconType == ICON_SMALL) || (iconType == 2/*ICON_SMALL2*/));
HICON hIcon = (smallIcon) ? GetHIconSm() : GetHIcon();
if (hIcon == NULL) {
hIcon = (smallIcon) ? AwtToolkit::GetInstance().GetAwtIconSm() :
hIcon = (smallIcon) ? AwtToolkit::GetInstance().GetAwtIconSm(reinterpret_cast<void*>(this)) :
AwtToolkit::GetInstance().GetAwtIcon();
}
return hIcon;
@@ -2009,6 +2022,17 @@ Java_sun_awt_windows_WFramePeer_synthesizeWmActivate(JNIEnv *env, jobject self,
CATCH_BAD_ALLOC;
}
JNIEXPORT void JNICALL
Java_sun_awt_windows_WFramePeer_updateIcon(JNIEnv *env, jobject self)
{
TRY;
AwtToolkit::GetInstance().InvokeFunction(_UpdateIcon, env->NewGlobalRef(self));
// global ref is deleted in _UpdateIcon()
CATCH_BAD_ALLOC;
}
} /* extern "C" */
static bool SetFocusToPluginControl(HWND hwndPlugin)

View File

@@ -1866,7 +1866,7 @@ HICON AwtToolkit::GetAwtIcon()
return ::LoadIcon(GetModuleHandle(), TEXT("AWT_ICON"));
}
HICON AwtToolkit::GetAwtIconSm()
HICON AwtToolkit::GetAwtIconSm(void* pAwtWindow)
{
static HICON defaultIconSm = NULL;
static int prevSmx = 0;
@@ -1875,6 +1875,16 @@ HICON AwtToolkit::GetAwtIconSm()
int smx = GetSystemMetrics(SM_CXSMICON);
int smy = GetSystemMetrics(SM_CYSMICON);
if (AwtWin32GraphicsDevice::IsUiScaleEnabled() && pAwtWindow != NULL) {
AwtWindow *wnd = reinterpret_cast<AwtWindow*>(pAwtWindow);
Devices::InstanceAccess devices;
AwtWin32GraphicsDevice* device = devices->GetDevice(AwtWin32GraphicsDevice::DeviceIndexForWindow(wnd->GetHWnd()));
if (device) {
smx = 16 * device->GetScaleX();
smy = 16 * device->GetScaleY();
}
}
// Fixed 6364216: LoadImage() may leak memory
if (defaultIconSm == NULL || smx != prevSmx || smy != prevSmy) {
defaultIconSm = (HICON)LoadImage(GetModuleHandle(), TEXT("AWT_ICON"), IMAGE_ICON, smx, smy, 0);

View File

@@ -370,7 +370,7 @@ public:
/* Return the current application icon. */
HICON GetAwtIcon();
HICON GetAwtIconSm();
HICON GetAwtIconSm(void* pAwtWindow = NULL);
// Calculate a wave-like value out of the integer 'value' and
// the specified period.

View File

@@ -1300,8 +1300,8 @@ MsgRouting AwtWindow::WmMove(int x, int y)
// NOTE: See also AwtWindow::Reshape
return mrDoDefault;
}
// Check for the new screen and update the java peer
CheckIfOnNewScreen(false); // postpone if different DPI
if (CheckIfOnNewScreen(false)) DoUpdateIcon();
/* Update the java AWT target component's fields directly */
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
@@ -1672,7 +1672,7 @@ int AwtWindow::GetScreenImOn() {
* Check to see if we've been moved onto another screen.
* If so, update internal data, surfaces, etc.
*/
void AwtWindow::CheckIfOnNewScreen(BOOL force) {
BOOL AwtWindow::CheckIfOnNewScreen(BOOL force) {
int curScrn = GetScreenImOn();
if (curScrn != m_screenNum) { // we've been moved
@@ -1686,7 +1686,7 @@ void AwtWindow::CheckIfOnNewScreen(BOOL force) {
if (oldDevice->GetScaleX() != newDevice->GetScaleX()
|| oldDevice->GetScaleY() != newDevice->GetScaleY()) {
// scales are different, wait for WM_DPICHANGED
return;
return TRUE;
}
}
@@ -1694,21 +1694,23 @@ void AwtWindow::CheckIfOnNewScreen(BOOL force) {
jclass peerCls = env->GetObjectClass(m_peerObject);
DASSERT(peerCls);
CHECK_NULL(peerCls);
CHECK_NULL_RETURN(peerCls, TRUE);
jmethodID draggedID = env->GetMethodID(peerCls, "draggedToNewScreen",
"()V");
DASSERT(draggedID);
if (draggedID == NULL) {
env->DeleteLocalRef(peerCls);
return;
return TRUE;
}
env->CallVoidMethod(m_peerObject, draggedID);
m_screenNum = curScrn;
env->DeleteLocalRef(peerCls);
return TRUE;
}
return FALSE;
}
// The shared code is not ready to the top-level window which crosses a few

View File

@@ -128,7 +128,7 @@ public:
virtual void RecalcNonClient();
virtual void RedrawNonClient();
virtual int GetScreenImOn();
virtual void CheckIfOnNewScreen(BOOL force);
virtual BOOL CheckIfOnNewScreen(BOOL force);
virtual void Grab();
virtual void Ungrab();
virtual void Ungrab(BOOL doPost);