8286872: Refactor add/modify notification icon (TrayIcon)

Reviewed-by: azvegint, kizune, honkar
This commit is contained in:
Alexey Ivanov 2022-05-19 20:04:19 +00:00
parent b0892295ee
commit 9f562ef754
2 changed files with 21 additions and 12 deletions
src/java.desktop/windows/native/libawt/windows

@ -496,11 +496,7 @@ MsgRouting AwtTrayIcon::WmTaskbarCreated() {
// Update the icon image
item->m_trayIcon->UpdateImage();
}
BOOL result = item->m_trayIcon->SendTrayMessage(NIM_ADD);
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
if (result) {
item->m_trayIcon->SendTrayMessage(NIM_SETVERSION);
}
item->m_trayIcon->AddTrayIcon();
}
m_bDPIChanged = false;
return mrDoDefault;
@ -748,7 +744,7 @@ void AwtTrayIcon::SetToolTip(LPCTSTR tooltip)
_tcscpy_s(m_nid.szTip, TRAY_ICON_TOOLTIP_MAX_SIZE, tooltip);
}
SendTrayMessage(NIM_MODIFY);
ModifyTrayIcon();
}
void AwtTrayIcon::_SetToolTip(void *param)
@ -816,10 +812,10 @@ void AwtTrayIcon::_UpdateIcon(void *param)
JNI_CHECK_PEER_GOTO(self, ret);
trayIcon = (AwtTrayIcon *)pData;
BOOL result = trayIcon->SendTrayMessage(jupdate == JNI_TRUE ? NIM_MODIFY : NIM_ADD);
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
if (result && jupdate == JNI_FALSE) {
trayIcon->SendTrayMessage(NIM_SETVERSION);
if (jupdate == JNI_TRUE) {
trayIcon->ModifyTrayIcon();
} else {
trayIcon->AddTrayIcon();
}
ret:
env->DeleteGlobalRef(self);
@ -868,7 +864,7 @@ void AwtTrayIcon::DisplayMessage(LPCTSTR caption, LPCTSTR text, LPCTSTR msgType)
_tcscpy_s(m_nid.szInfo, TRAY_ICON_BALLOON_INFO_MAX_SIZE, text);
}
SendTrayMessage(NIM_MODIFY);
ModifyTrayIcon();
m_nid.uFlags &= ~NIF_INFO;
}

@ -52,7 +52,6 @@ public:
virtual void Dispose();
BOOL SendTrayMessage(DWORD dwMessage);
void LinkObjects(JNIEnv *env, jobject peer);
void UnlinkObjects();
@ -154,6 +153,20 @@ private:
TrayIconListItem* m_next;
};
BOOL SendTrayMessage(DWORD dwMessage);
INLINE void AddTrayIcon() {
BOOL result = SendTrayMessage(NIM_ADD);
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
if (result) {
SendTrayMessage(NIM_SETVERSION);
}
}
INLINE void ModifyTrayIcon() {
SendTrayMessage(NIM_MODIFY);
}
static bool m_bDPIChanged;
public: